package com.ymttest.business.service;

import java.io.IOException;
import java.math.BigDecimal;
import java.security.PrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;

import org.apache.commons.collections.CollectionUtils;
import org.apache.http.client.ClientProtocolException;
import org.junit.experimental.theories.suppliers.TestedOn;

import com.ymatou.iapi.payment.parameter.AcquireOrderBean;
import com.ymatou.iapi.payment.parameter.AcquireRefundBean;
import com.ymatou.iapi.payment.parameter.AliPayNotifyBean;
import com.ymatou.iapi.payment.parameter.AliPayWapCallBackBean;
import com.ymatou.iapi.payment.parameter.AliPayWapNotifyBean;
import com.ymatou.iapi.payment.parameter.ApproveRefundBean;
import com.ymatou.iapi.payment.parameter.ExecuteRefundBean;
import com.ymatou.iapi.payment.parameter.FastRefundBean;
import com.ymatou.iapi.payment.parameter.HbFq;
import com.ymatou.iapi.payment.parameter.HipoNotifyBean;
import com.ymatou.iapi.payment.parameter.RefundNotifyBean;
import com.ymatou.iapi.payment.parameter.RegFqlMemberBean;
import com.ymatou.iapi.payment.parameter.SubmitRefundBean;
import com.ymatou.iapi.payment.parameter.TradeDetail;
import com.ymatou.iapi.payment.parameter.WeiXinNotifyBean;
import com.ymatou.iapi.payment.service.AcquireOrderCall;
import com.ymatou.iapi.payment.service.AcquireRefundCall;
import com.ymatou.iapi.payment.service.ApproveRefundCall;
import com.ymatou.iapi.payment.service.ExecuteRefundCall;
import com.ymatou.iapi.payment.service.FastRefundCall;
import com.ymatou.iapi.payment.service.RegFqlMemberCall;
import com.ymatou.iapi.payment.service.SubmitRefundCall;
import com.ymatou.paygetway.parameter.ApplePayNotifyBean;
import com.ymatou.paygetway.parameter.ApplePayRefundNotifyBean;
import com.ymatou.paygetway.parameter.BaoFuNotifyBean;
import com.ymatou.paygetway.parameter.BaoFuRefundNotifyBean;
import com.ymatou.paygetway.parameter.BestPayNotifyBean;
import com.ymatou.paygetway.parameter.CMBNotifyBean;
import com.ymatou.paygetway.parameter.CMBSignNotifyBean;
import com.ymatou.paygetway.parameter.HipoNotifyH5Bean;
import com.ymatou.paygetway.parameter.NoticeData;
import com.ymatou.paygetway.parameter.OrderNotifyBean;
import com.ymatou.paygetway.parameter.PNoticeData;
import com.ymatou.paygetway.parameter.SFTNotifyBean;
import com.ymatou.paygetway.parameter.SFTRefundNotifyBean;
import com.ymatou.paygetway.parameter.SNoticeData;
import com.ymatou.paygetway.parameter.UserNotifyBean;
import com.ymatou.paygetway.service.HipoPayNotifyCall;
import com.ymatou.paygetway.service.HipoPayNotifyH5Call;
import com.ymatou.paygetway.service.NotifyCall;
import com.ymatou.paygetway.service.NotifyCall50;
import com.ymatou.paygetway.service.NotifyCall70;
import com.ymatou.paygetway.service.OrderNotifyCall;
import com.ymatou.paygetway.service.RefundNotifyCall;
import com.ymatou.paygetway.service.UserNotifyCall;
import com.ymt.base.BaseCall;
import com.ymt.base.YmatouEasyCall;
//import com.ymatou.paymentproxy.parameter.AcquireOrderBean;
//import com.ymatou.paymentproxy.parameter.AliPayNotifyBean;
//import com.ymatou.paymentproxy.parameter.AliPayWapCallBackBean;
//import com.ymatou.paymentproxy.parameter.AliPayWapNotifyBean;
//import com.ymatou.paymentproxy.parameter.FastRefundBean;
//import com.ymatou.paymentproxy.parameter.HbFq;
//import com.ymatou.paymentproxy.parameter.RefundNotifyBean;
//import com.ymatou.paymentproxy.parameter.SubmitRefundBean;
//import com.ymatou.paymentproxy.parameter.TradeDetail;
//import com.ymatou.paymentproxy.parameter.WeiXinNotifyBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.core.tool.RSAUtils;
import com.ymt.util.DataManager;
import com.ymttest.business.data.Sign;
import com.ymttest.business.data.applepaysign.ApplePayConstants;
import com.ymttest.business.data.applepaysign.Hex;
import com.ymttest.business.data.applepaysign.SecurityUtil;
import com.ymttest.business.service.shenqi.DGSQBaseService;
import com.ymttest.common.enums.BankIdEnum;
import com.ymttest.database.model.MPayment;
import com.ymttest.database.model.MRefund;
//import com.ymttest.database.model.PPBussinessOrder;
//import com.ymttest.database.model.PPPayment;
//import com.ymttest.database.model.RefundRequest;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.PayGateWayWapper;
//import com.ymttest.database.sqlwapper.PayGateWayWapper;
import com.ymttest.utils.BaofooSignature;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

public class PayGateWayCallService {
	/**
	 * GodAliPayPc
	 */
	public static String GODAliPay_MERID="2088631638260360";
	public static String GODAliPay_EMAIL="merchant_ymt@163.com";
	/**
	 * 盛付通商户号 paymode3
	 */
	public static String SFTMerchantNo="30057909";
	public static String SFTMerchantKey="es839gnc88skjgsft";
	/**
	 * 抖音支付需要用到的openid
	 */
	public static String TouTiaoOpenId="iP9odhfdqOh0t50-";
	public static String TouTiao_MERID="1900012778";
	public static String TouTiao_EMAIL="ap.ymt@ymatou.com";
	public static String TouTiao_AppId="800127786710";
	/**
	 * youngcloud 全球优选用 3117-替换3017
	 */
		public static String Alipay_MERID_YC="2088531231813775";
		public static String Alipay_EMAIL_YC="youngcloud@youngoceancloud.com";
		public static String WX_QQG_AppID_YC = "wxef012229113b2d43";
		public static String WX_QQG_merchantId_YC="1545048211" ;
		//3015-3115
		public static String WX_QQG_AppID2_YC = "wx8520293850d0c516";
		public static String WX_QQG_merchantId2_YC="1545048211" ;
		
//		/**
//		 * 全球优选用-洋云 3117 20190820 变更
//		 */
//		public static final String WX_QQG_merchantId_Could_YC = "1545048211";
//		public static final String WX_QQG_AppID_Could_15_YC  = "wx8520293850d0c516";
//		public static final String WX_QQG_AppID_Could_17_YC = "wxef012229113b2d43";
		
	/**
	 * 分期乐代理商户号
	 */
	public final static Integer FQLAgent=1099400;
	/**
	 * 支付用独立小程序商户id
	 */
	public final static Integer PayGdSq=500009815;
	/**
	 * sq独立小程序appname-查询接口测试用
	 */
	public final static String GdSq="500064783";
	/**
	 *  sqh5独立小程序appname-查询接口测试用
	 */
	public final static String GdH5Sq="500009816";
	/**
	 * 测试环境商户号
	 */
//	public final static String GdDefMerchantNo="WC5c6557f0a013b";
	/**
	 * hipopay测试环境商户号-new 20190325 飞界国际 paymode1 alipaymode1 6000 6001
	 */
	public final static String GdDefMerchantNo="WC5c78d78282173";
	/**
	 * hipopay测试环境商户号-new 20190930 6001迁6002 飞界国际电子商务 paymode2 6002 6003
	 */
	public final static String GdDefMerchantNo_6002="WC5d8d865dd40fc";
	//MchNo
	public final static String GdH5sqBuyerMerchantNo_6011="30057909";
	/**
	 * 港币汇率 mock用
	 */
	public final static String HKExchangeRate="1.169590643274853801169590643";
	/**
	 * 英镑
	 */
	public final static String GBPExchangeRate="9.0992154762";
	/**
	 * hipo收单用的真实openid 用于测试沙箱环境
	 */
//	public final static String HipoPayWxAppOpenId="o2q5Z5MV02lePMGBBOk6WRr_wW1w";
	
	/**
	 *  hipo收单用的真实openid 用于测试沙箱环境-环境切换
	 */
	public final static String HipoPayWxAppOpenId="owbCH5JFEZTRRnb8JKyLQtj3aWEk";
	/**
	 *  hipo收单用的真实openid 用于测试沙箱环境-环境切换
	 *  "openId": "obdix0ukF6yD9bybG_6ax6h-Q3V8",
	 */
	public final static String HipoPayWxH5OpenId="obdix0ukF6yD9bybG_6ax6h-Q3V8";
	
//	appid：wx8cd48735c8606833
	public final static String HipoPayWxAppId="wx8cd48735c8606833";
	/**
	 * 6010
	 */
	public final static String SFTWxOpenId="ojIpa5EUOdzXNrTobRkzZSMmiDQ0";
	public final static String SFTH5OpenId="ojIpa5EUOdzXNrTobRkzZSMmiDQ0";
	/**
	 * 配置渠道
	 * disconf payment  domain-pay.properties  payTypeRouter=60->61
	 */
	public static Boolean OpenYangYi=true;
	/**
	 * 招商
	 */
	public static String CMB_SITMERID="000157";
	/**
	 * 洋云-全球优选用
	 */
	public static String Alipay_MERID_Could="2088531231813775";
	public static String Alipay_EMAIL_Could="youngcloud@youngoceancloud.com";
	/**
	 * 测试环境applepay商户号
	 */
	public static String Alipay_MERID="2088701734809577";
	public static String Alipay_LOGIN_MERID="2088701734809577";
	public static String Alipay_EMAIL="ap.ymt@ymatou.com";
	//	public static String APPLEPAY_MERID_OLD = "308310053994237";
	public static String APPLEPAY_MERID = "310310153990887";
	/**
	 * 宝付 废弃
	 */
	public static String BaoFu_MERID = "1192439";
	public static String BaoFu_TerminalID = "36657";
	public static String WX_DefAppID = "wxf51a439c0416f182";
	public static String WX_AppID = "wx3b7bb547aea2ffa3";
	/**
	 * 翼支付
	 */
	public static String BESTPAY_MERID = "02310103010604409";
	
	public static String WX_App_merchantId="1234079001";
	public static String WX_Wap_merchantId="1278350701";
	
	/**
	 * 小米支付
	 */
	public static String UPAY_MERID = "310310153990890";
	public static String UPAY_CertId="73657647234";
	/**
	 * 海外直播扫货 201804
	 */
	public static String WX_HS_AppID = "wx73a8dffe5d5a41e4";
	public static String WX_HS_merchantId="1501932491" ;
	
	/**
	 * 分销-全球购-201809 小程序用 3017
	 * 1499306082（wxef012229113b2d43）
	 * 
	 */
	public static String WX_QQG_AppID = "wxef012229113b2d43";
	public static String WX_QQG_merchantId="1502964581" ;
	/**
	 * 分销-全球购-wxapp
	 * app用 3015
	 * 
	 */
	public static String WX_QQG_AppID2 = "wx1b96879e3771b8c4";
	public static String WX_QQG_merchantId2="1502964581" ;
	/**
	 * 直播微店
	 */
	public static String LiveShop_merchantId="1499306082" ;
	public static String LiveShop_AppId="wx72755ce3365bb882";
	//Sign迁移过来的 测试用掩码
	public static final String autoTestKey = "autotestsalt";

	public static final String weixinAppKey = "c5781df6b8f149adca6094cdac4ac684";
	public static final String weixinJSAPIKey = "es839gnc8451lp0s943n568xzskjgdbv";

	public static final String newweixinAppKey = "autotestsalt";
	public static final String newweixinJSAPIKey = "autotestsalt";
	/**
	 * 全球优选用-洋云
	 */
	public static final String WX_QQG_merchantId_Could = "1545048211";
	public static final String WX_QQG_AppID_Could_15  = "wx8520293850d0c516";
	public static final String WX_QQG_AppID_Could_17  = "wxef012229113b2d43";
	/**
	 * 鱼多多
	 */
	public static final String WX_QQG_AppID_Could_15_YDD  ="wx2d5cf5f183a0366c";
	/**
	 * 收单的时候传入的mchid 测试用
	 */
	public static Integer TestMchId=500680446;
	static{
		if(OpenYangYi){
			initYangYiMERID();
		}
	}
	/**
	 * 码头用户注册分期乐
	 * @param userid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void RegFqlMember(Integer userid) throws ClientProtocolException, IOException{
		RegFqlMemberBean regfqlmemberBean=new RegFqlMemberBean();
		RegFqlMemberCall regfqlmemberCall=new RegFqlMemberCall();
		regfqlmemberBean.setUserId(userid);
		regfqlmemberCall.setData(regfqlmemberBean);
		regfqlmemberCall.callService();			
	}
	/**
	 * 初始化分期乐CodeCallback
	 * @return
	 */
	public static UserNotifyBean initFQLCodeCallback(Integer userid){
//		type	int	是	8000	消息类型
//		third_uid	string	是		商户用户唯一id
//		code	string	是		用户oauth鉴权code
//		time	long	是	1	消息时间
//		method	string	是	fenqile.auth.callback	消息场景
//		sign	string	是		消息签名						采用POP签名
		UserNotifyBean usernotifyBean=new UserNotifyBean();
		usernotifyBean.setType(8000);
		usernotifyBean.setThird_uid(userid.toString());
		usernotifyBean.setCode(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
		usernotifyBean.setTime(YMTDateUtil.getDate().getTime());
		usernotifyBean.setMethod("fenqile.auth.callback");
		usernotifyBean.setSign("1");
		return usernotifyBean;
	}
	/**
	 * 添加mock头
	 * @param cpcall
	 * @param m
	 */
	public static void addMock(BaseCall cpcall, Map m) {
		Logger.comment("初始化MockHeader信息:" + m.toString());
		Set sl = m.entrySet();
		for (Object o : sl) {
			String[] ss = o.toString().split("=");
			String value = FormatUtil.urlEncode(ss[1]);
			cpcall.addHeader(ss[0], value);
		}
	}
	/**
	 * 获取code成功 用于授信前置条件 授信的参数设置要在这之后做--公用bean call
	 * @param uid
	 * @throws Exception
	 */
	public static Map CodeFin(Integer uid) throws Exception {
		PayGateWayCallService.RegFqlMember(uid); 
		UserNotifyCall usernotifyCall=new UserNotifyCall();
		UserNotifyBean usernotifyBean=new UserNotifyBean();
		usernotifyBean=PayGateWayCallService.initFQLCodeCallback(uid);
		usernotifyCall.setData(usernotifyBean);
		Map mcode=CodeMockMap();
		addMock(usernotifyCall, mcode);
		usernotifyCall.callService();
		usernotifyBean=new UserNotifyBean();
		usernotifyCall=new UserNotifyCall();
		return mcode;
	}
	/**
	 * fql 多uid绑定同一个openid场景
	 * @param uid
	 * @param openid
	 * @return
	 * @throws Exception
	 */
	public static Map CodeFin(Integer uid,String openid) throws Exception {
		PayGateWayCallService.RegFqlMember(uid); 
		UserNotifyCall usernotifyCall=new UserNotifyCall();
		UserNotifyBean usernotifyBean=new UserNotifyBean();
		usernotifyBean=PayGateWayCallService.initFQLCodeCallback(uid);
		usernotifyCall.setData(usernotifyBean);
		Map mcode=CodeMockMap();
		mcode.put("MockResult-FqlPay-open_id", openid);
		addMock(usernotifyCall, mcode);
		usernotifyCall.callService();
		usernotifyBean=new UserNotifyBean();
		usernotifyCall=new UserNotifyCall();
		return mcode;
	}

	/**
	 * 授权 用于支付回调前置
	 * @param userid
	 * @param openid
	 * @return
	 * @throws Exception
	 */
	public static Map CreditFin(Integer userid,String openid,boolean success) throws Exception {
		UserNotifyCall usernotifyCall=new UserNotifyCall();
		UserNotifyBean usernotifyBean=new UserNotifyBean();
		usernotifyBean=PayGateWayCallService.initFQLCreditCallback(userid);
		usernotifyBean.setOpen_id(openid);
		usernotifyCall.setData(usernotifyBean);
		Map mcredit=CreditMockMap();
		if(!success) {
			usernotifyBean.setType(1005);
		}
		addMock(usernotifyCall, mcredit);
		usernotifyCall.callService();
		if(!usernotifyCall.getReturnData().contains("0")) {
			Thread.sleep(3000);
			usernotifyCall.callService();
		}
//		usernotifyBean=new UserNotifyBean();
//		usernotifyCall=new UserNotifyCall();
		return mcredit;
	}
	public static Map CreditFin(Integer userid,String openid) throws Exception {
		return CreditFin(userid, openid, true);
	}
	/**
	 * 默认获取code mock
	 * @return
	 * @throws Exception
	 */
	public static Map CodeMockMap() throws Exception {
		Logger.comment("获取默认的Mock信息");
		Map m = new HashMap<String, String>();
		m.put("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		m.put("MockId", mockid);
		String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
		m.put("MockResult-FqlPay-open_id", openid);
//		usernotifyCall.addHeader("MockResult-FqlPay-open_id", openid);
		String rtoken=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
		m.put("MockResult-FqlPay-refresh_token", rtoken);
//		usernotifyCall.addHeader("MockResult-FqlPay-refresh_token", rtoken);
		String atoken=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
		m.put("MockResult-FqlPay-access_token", atoken);
//		usernotifyCall.addHeader("MockResult-FqlPay-access_token", atoken);
		return m;
	}
	/**
	 * 默认获取Credit mock
	 * @return
	 * @throws Exception
	 */
	public static Map CreditMockMap() throws Exception {
		Logger.comment("获取默认的Mock信息");
		Map m = new HashMap<String, String>();
		m.put("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		m.put("MockId", mockid);
//		MockResult-FqlPay-total_credit: 500
		m.put("MockResult-FqlPay-total_credit", 600);
//		MockResult-FqlPay-total_avl_credit: 200
		m.put("MockResult-FqlPay-total_avl_credit", 210);
//		MockResult-FqlPay-new_user_flag: 1
		m.put("MockResult-FqlPay-new_user_flag", 2);
//		MockResult-FqlPay-credit_grant_time: 2019-06-14 17:50:38
		m.put("MockResult-FqlPay-credit_grant_time", YMTDateUtil.getBeforeOrNextDay(0));
//		MockResult-FqlPay-max_overdue: 1
		m.put("MockResult-FqlPay-max_overdue", 12);
//		MockResult-FqlPay-user_repay_day: 2
		m.put("MockResult-FqlPay-user_repay_day", 2);
//		MockResult-FqlPay-month: 3
		m.put("MockResult-FqlPay-month", Calendar.getInstance().get(Calendar.MONTH));
//		MockResult-FqlPay-year: 2019
		m.put("MockResult-FqlPay-year", Calendar.getInstance().get(Calendar.YEAR));
//		MockResult-FqlPay-total_un_repay_amount: 2000
		m.put("MockResult-FqlPay-total_un_repay_amount",2000);
		return m;
	}
	/**
	 * 初始化分期乐creditCallback
	 * @return
	 */
	public static UserNotifyBean initFQLCreditCallback(Integer userid){
//		type	int	是	1000	消息类型
//		open_id	string	否	4b89296f7f2a6b3ba88c3a460a66adssfd19ed	分期乐分配的用户openid如果商户未执行本文档中的1.2（code换open_id），则此字段可能返回为空
//		agent	string	是	1082468	
//		order_id	sttinr	是	O2019020154845688	授信订单id
//		time	long	是	1	消息时间
//		method	string	是	fenqile.credit.callback	消息场景
//		sign	int	是		消息签名						采用POP签名

		UserNotifyBean usernotifyBean=new UserNotifyBean();
		usernotifyBean.setType(1000);
		usernotifyBean.setOpen_id(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
		usernotifyBean.setAgent(FQLAgent.toString());
		usernotifyBean.setOrder_id(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
		usernotifyBean.setTime(YMTDateUtil.getDate().getTime());
		usernotifyBean.setMethod("fenqile.credit.callback");
		usernotifyBean.setSign("1");
		return usernotifyBean;
	}
	/**
	 *  修改type洋漪
	 * @param acquireorderBean
	 */
	public static void initType(AcquireOrderBean acquireorderBean){
		if(OpenYangYi){
			Logger.comment("渠道切换洋漪type逻辑:"+OpenYangYi);
			if(acquireorderBean.getPayType().equals("10")){
				acquireorderBean.setPayType("1010");
			}else if(acquireorderBean.getPayType().equals("9")){
				acquireorderBean.setPayType("1009");
			}else if(acquireorderBean.getPayType().equals("11")){
				acquireorderBean.setPayType("1011");
			}
			else if(acquireorderBean.getPayType().equals("13")){
				acquireorderBean.setPayType("1013");
			}
			else if(acquireorderBean.getPayType().equals("14")){
				acquireorderBean.setPayType("1014");
			}
			else if(acquireorderBean.getPayType().equals("15")){
				acquireorderBean.setPayType("1015");
			}
			else if(acquireorderBean.getPayType().equals("16")){
				acquireorderBean.setPayType("1016");
			}
			else if(acquireorderBean.getPayType().equals("17")){
				acquireorderBean.setPayType("1017");
			}
			else if(acquireorderBean.getPayType().equals("19")){
				acquireorderBean.setPayType("1019");
			}
		}
	}
	/**
	 * 初始化洋漪商户
	 */
	public static void initYangYiMERID(){
		PayGateWayCallService.Alipay_MERID="2088031615307556";
		PayGateWayCallService.Alipay_EMAIL="ap.yy@youngeasy.com";
		WX_App_merchantId="1499306082";
		WX_Wap_merchantId="1499306082";
		WX_HS_merchantId="1499306082";
	}
	

	/**
	 * 初始化码头商户
	 */
	public static void initYMatouMERID(){
		 Alipay_MERID="2088701734809577";
		 Alipay_EMAIL="ap.ymt@ymatou.com";
		 APPLEPAY_MERID = "310310153990887";
		 BaoFu_MERID = "1192439";
		 BaoFu_TerminalID = "36657";
		 WX_DefAppID = "wxf51a439c0416f182";
		 WX_AppID = "wx3b7bb547aea2ffa3";
		 BESTPAY_MERID = "02310103010604409";
		
		 WX_App_merchantId="1234079001";
		 WX_Wap_merchantId="1278350701";
		
		 WX_HS_AppID = "wx73a8dffe5d5a41e4";
		 WX_HS_merchantId="1501932491" ;
		 LiveShop_merchantId="1499306082" ;
		 LiveShop_AppId="wx72755ce3365bb882";
	}
	/**
	 * 初始化HipoNotify
	 * @param aqb
	 * @param exchange_rate 汇率
	 * @return
	 * @throws InterruptedException
	 */
	public static HipoNotifyBean initHipoNotifyBean(AcquireOrderBean aqb,String exchange_rate) throws InterruptedException {
		HipoNotifyBean hipoNotifyBean=new HipoNotifyBean();
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		hipoNotifyBean.setAmount(aqb.getPayPrice());
		//结算？
		hipoNotifyBean.setCurrency("CNY");
		hipoNotifyBean.setExchange_rate(exchange_rate);
		hipoNotifyBean.setFinish_time(YMTDateUtil.getBeforeOrNextSecond(-1, "yyyy-MM-dd HH:mm:ss"));
		hipoNotifyBean.setOut_trade_id(trandno);
		hipoNotifyBean.setPay_amount(aqb.getPayPrice());
		hipoNotifyBean.setPay_currency("CNY");
		hipoNotifyBean.setPayment_no(TestDataManager.getRandomUUID().toString().replace("-", "").substring(0, 31));
		hipoNotifyBean.setStatus("PAID");
		hipoNotifyBean.setTrade_time(YMTDateUtil.getBeforeOrNextSecond(-10, "yyyy-MM-dd HH:mm:ss"));
		hipoNotifyBean.setTrade_type("MINIPROGRA");
		return hipoNotifyBean;
	}
	/**
	 * @param aqb
	 * @param exchange_rate 汇率
	 * @return
	 * @throws InterruptedException 
	 */
	public static  HipoNotifyH5Bean initHipoH5NotifyBean(AcquireOrderBean aqb,String exchange_rate) throws InterruptedException {
		HipoNotifyH5Bean HipoNotifyH5Bean=new HipoNotifyH5Bean();
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		HipoNotifyH5Bean.setAmount(aqb.getPayPrice());
		//结算？
		HipoNotifyH5Bean.setCurrency("CNY");
		HipoNotifyH5Bean.setExchange_rate(exchange_rate);
		HipoNotifyH5Bean.setTrade_time(YMTDateUtil.getBeforeOrNextSecond(-1, "yyyy-MM-dd HH:mm:ss"));
		HipoNotifyH5Bean.setAgent_order_id(trandno);
		HipoNotifyH5Bean.setPay_amount(aqb.getPayPrice());
		HipoNotifyH5Bean.setPay_currency("CNY");
		HipoNotifyH5Bean.setNo(TestDataManager.getRandomUUID().toString().replace("-", "").substring(0, 31));
		HipoNotifyH5Bean.setStatus("PAID");
		HipoNotifyH5Bean.setTrade_time(YMTDateUtil.getBeforeOrNextSecond(-10, "yyyy-MM-dd HH:mm:ss"));
		HipoNotifyH5Bean.setTrade_type("MINIPROGRA");
		HipoNotifyH5Bean.setOpenid(aqb.getOpenId());
		return HipoNotifyH5Bean;
	}
	/**
	 * 初始化分期乐订单回调
	 * @param aqb
	 * @return
	 * @throws InterruptedException
	 */
	public static OrderNotifyBean initFQLOrderNotifyBean(AcquireOrderBean aqb) throws InterruptedException {
		OrderNotifyBean ordernotifyBean2=new OrderNotifyBean();
		MPayment ppm = new MPayment();
		try {
			ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
		}catch (Exception e) {
		}
		String trandno = ppm.getPaymentId();
		ordernotifyBean2.setAmount(aqb.getPayPrice());
		ordernotifyBean2.setAttach("attach");
		ordernotifyBean2.setBody("body");
		ordernotifyBean2.setMerch_sale_state(12);
		ordernotifyBean2.setMsg("成功");
		ordernotifyBean2.setOrder_id(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
		ordernotifyBean2.setSign("");
		ordernotifyBean2.setSubject("subject");
		ordernotifyBean2.setThird_order_id(trandno);
		ordernotifyBean2.setThird_refund_id(null);
		return ordernotifyBean2;
	}
	/**
	 * 初始化一个AcquireOrderBean 收单用
	 * 
	 * @return AcquireOrderBean
	 * @throws InterruptedException
	 */
	public static AcquireOrderBean initAcquireOrder(String type)
			throws InterruptedException {
		Logger.comment("初始化默认AcquireOrderBean,支付网关收单");
		
		String orderid = TestDataManager.getClientpaymentId();
		String payPrice = String.valueOf(new Random().nextInt(5) + 2);
		String productName = "自动化测试商品" + TestDataManager.randomStr(10);
		// Map m = new DefaultWapper().selectLastWeixinUser();
		String uid = new JUserWapper().selectWXUser().getUserId().toString();
		// String uid ="1";
		String ip = TestDataManager.getRandomIp();
		AcquireOrderBean acquireorderBean = new AcquireOrderBean();
		acquireorderBean.setAppId("AutoTest");
		acquireorderBean.setBankId(BankIdEnum.CMB.name());
		// 定金或者支付
		acquireorderBean.setBizCode("3");
		acquireorderBean.setCallbackUrl("http://www.ymatou.com/pay/result");
		acquireorderBean.setCurrency("CNY");
		acquireorderBean.setEncoding("65001");
		acquireorderBean
				.setExt("{\"SHOWMODE\":\"2\",\"PAYMETHOD\":\"2\", \"IsHangZhou\":1}");
		acquireorderBean
				.setNotifyUrl("http://mockforpay.iapi.ymatou.com/api/Trading/NotifyTradingEvent");
		acquireorderBean.setOrderId(orderid);
		acquireorderBean.setOrderTime(YMTDateUtil.getSysTime("yyyyMMddHHmmss"));
		acquireorderBean.setOriginAppId("AutoTest");
		acquireorderBean.setPayPrice(payPrice);
		acquireorderBean.setPayType(type);
		//新渠道
		if (type.equals("60")) {
			acquireorderBean.setPayType("61");
		}
		//20190930 hipoay导流到6002 飞界国际
		if (type.equals("6001")) {
			acquireorderBean.setPayType("6002");
		}
		//HipoPayAliWap
		if (type.equals("6006")) {
			acquireorderBean.setSettleCurrency("HKD");
			acquireorderBean.setAppName("wxsqBuyer");
		}
		if (type.equals("6103")||type.equals("6107")) {
			acquireorderBean.setSettleCurrency("HKD");
			acquireorderBean.setAppName("appsqSeller");
			acquireorderBean.setBizCode("60");
		}
		acquireorderBean.setProductName(productName);
		acquireorderBean.setSignMethod("MD5");
		if (type.equals("13") || type.equals("9")|| type.equals("3013")|| type.equals("3113")|| type.equals("3213")|| type.equals("8")|| type.equals("2013")|| type.equals("4013")) {
			acquireorderBean.setSignMethod("RSA");
			if (type.equals("9")) {
				acquireorderBean.setInstallmentNum(3);
			}
		}
		if (type.equals("2013")) {
			acquireorderBean.setOpenId(TouTiaoOpenId);
		}
		if (type.equals("70")) {
			String sign = new Sign()
					.signMd5(acquireorderBean, Sign.autoTestKey);
			acquireorderBean.setSign(sign);
		}
		//3017的bizcode为33
		if (type.equals("3017")||type.equals("3015")||type.equals("3013")|| type.equals("3113")|| type.equals("3115")|| type.equals("3213")|| type.equals("3215")|| type.equals("3117")) {
			acquireorderBean.setBizCode("33");
		}
		//6000 HipoPayWxAppOpenId 固定 因为需要真实的微信openid
		if (type.equals("6000")||type.equals("6001")||type.equals("6002")||type.equals("6003")||type.equals("6006")) {
			acquireorderBean.setSettleCurrency("HKD");
			acquireorderBean.setBizCode("60");
			acquireorderBean.setOpenId(HipoPayWxAppOpenId);
			if(type.equals("6001")||type.equals("6002")||type.equals("6003")) {
				acquireorderBean.setOpenId(HipoPayWxH5OpenId);
			}
			acquireorderBean.setAppName("wxsqBuyer");
			if(type.equals("6001")||type.equals("6002")||type.equals("6003")) {
				acquireorderBean.setAppName("h5sqBuyer");
				acquireorderBean.setOpenId(HipoPayWxH5OpenId);
				acquireorderBean.setSettleCurrency("HKD");
			}
			if(type.equals("6006")) {
				acquireorderBean.setAppName("wxsqBuyer");
				acquireorderBean.setBizCode("60");
			}
		}
		if(type.equals("6010")) {
			acquireorderBean.setOpenId(SFTWxOpenId);
			acquireorderBean.setAppName("wxsqBuyer");
			acquireorderBean.setBizCode("60");
		}else if(type.equals("6011")) {
			acquireorderBean.setOpenId(SFTWxOpenId);
			acquireorderBean.setAppName("h5sqBuyer");
			acquireorderBean.setBizCode("60");
		}
		acquireorderBean.setTraceId(TestDataManager.getRandomUUID().toString());
		acquireorderBean.setUserId(uid);
		acquireorderBean.setUserIp(ip);
		acquireorderBean.setVersion("1");
		acquireorderBean.setMemo("备注:" + TestDataManager.getRandomNum(3));
		//切换洋漪逻辑
		initType(acquireorderBean);
		//测试环境支付宝花呗8 -百度支付  用的是ymt渠道
		if(acquireorderBean.getPayType().equals("8")||acquireorderBean.getPayType().equals("4013")||acquireorderBean.getPayType().equals("4016")) {
			PayGateWayCallService.initYMatouMERID();
		}else {
			if(OpenYangYi){
				initYangYiMERID();
			}
		}
		return acquireorderBean;
	}

	/**
	 * 初始化Alipay bean 回调用
	 * 
	 * @param aqb
	 * @return
	 * @throws InterruptedException
	 */
	public static AliPayNotifyBean initAliPayNotifyBean(AcquireOrderBean aqb)
			throws InterruptedException {
		Logger.comment("初始化默认AliPayNotifyBean,支付网关阿里回调");
		AliPayNotifyBean alinotifyBean = new AliPayNotifyBean();
		alinotifyBean.setBody("自动化测试订单");
		alinotifyBean.setBusiness_scene("qrpay");
		alinotifyBean.setBuyer_email(TestDataManager.getEmail());
		alinotifyBean.setBuyer_id("2088" + TestDataManager.getRandomNum(10));
		alinotifyBean.setDiscount("-1");
		alinotifyBean.setExtra_common_param("自动化测试回传参数");
		alinotifyBean.setGmt_close(YMTDateUtil.getBeforeOrNextDay(1));
		alinotifyBean.setGmt_create(YMTDateUtil.getBeforeOrNextSecond(1));
		alinotifyBean.setGmt_payment(YMTDateUtil.getBeforeOrNextSecond(2));
		alinotifyBean.setGmt_refund(null);
		alinotifyBean.setIs_total_fee_adjust("N");
		alinotifyBean.setNotify_id(TestDataManager.getClientpaymentId());
		alinotifyBean.setNotify_time(YMTDateUtil.getBeforeOrNextSecond(3));
		alinotifyBean.setNotify_type("trade_status_sync");
		// trandno 是PaymentId
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		alinotifyBean.setOut_trade_no(trandno);
		alinotifyBean.setPayment_type("1");
		alinotifyBean.setPrice(aqb.getPayPrice());
		alinotifyBean.setQuantity("1");
		alinotifyBean.setRefund_status(null);
		alinotifyBean.setSeller_email(PayGateWayCallService.Alipay_EMAIL);
		alinotifyBean.setSeller_id(PayGateWayCallService.Alipay_MERID);
		if(aqb.getPayType().equals("3113")) {
			alinotifyBean.setSeller_email(PayGateWayCallService.Alipay_EMAIL_Could);
			alinotifyBean.setSeller_id(PayGateWayCallService.Alipay_MERID_Could);
		}
		if(aqb.getPayType().equals("3213")) {
			alinotifyBean.setSeller_email(PayGateWayCallService.Alipay_EMAIL_Could);
			alinotifyBean.setSeller_id(PayGateWayCallService.Alipay_MERID_Could);
		}
		if(aqb.getPayType().equals("2013")) {
			alinotifyBean.setSeller_email(PayGateWayCallService.TouTiao_EMAIL);
			alinotifyBean.setSeller_id(PayGateWayCallService.Alipay_LOGIN_MERID);
		}
		alinotifyBean.setSubject(aqb.getProductName());
		alinotifyBean.setTotal_fee(aqb.getPayPrice());
		alinotifyBean.setTrade_no(TestDataManager.getRandomUUID().toString());
		alinotifyBean.setTrade_status("TRADE_SUCCESS");
		alinotifyBean.setUse_coupon("N");
		//支付宝花呗分期回调标识
		if (aqb.getPayType().equals("9")||aqb.getPayType().equals("1009")) {
			alinotifyBean.setOut_channel_type("PCREDIT_CC_PCREDIT_INSTALLMENT");
		}
		return alinotifyBean;
	}

	/**
	 * 
	 * @param aqb
	 *            收单对象
	 * @param discountAmount
	 *            优惠金额 目前是0
	 * @return
	 * @throws Exception
	 */
	public static CMBNotifyBean initCMBNotifyBean(AcquireOrderBean aqb,
			String discountAmount) throws Exception {
		Logger.comment("初始化默认initCMBNotifyBean,支付网关招商支付回调");
		CMBNotifyBean cmbNotifyBean = new CMBNotifyBean();
		cmbNotifyBean.setCharset("UTF-8");
		cmbNotifyBean.setSignType("RSA");
		cmbNotifyBean.setVersion("1.0");
		// NoticeData
		PNoticeData noticeData = new PNoticeData();
		noticeData.setAmount(aqb.getPayPrice());
		noticeData.setBankDate(YMTDateUtil.getSysTime("yyyyMMdd"));
		noticeData.setBankSerialNo(TestDataManager.getRandomUUID().toString());
		noticeData.setBranchNo("0021");
		noticeData.setDate(YMTDateUtil.getSysTime("yyyyMMdd"));
		noticeData.setDateTime(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
		noticeData.setDiscountAmount(discountAmount);
		if (Double.valueOf(discountAmount) > 0) {
			noticeData.setDiscountFlag("Y");
		} else {
			noticeData.setDiscountFlag("N");
		}
		noticeData.setHttpMethod("POST");
		noticeData.setMerchantNo(CMB_SITMERID);

		if (EnvSetup.getEnv().equals("uat")) {

			noticeData.setMerchantNo("006489");

		}
		noticeData.setMerchantPara("Pay");
		noticeData
				.setNoticeSerialNo(TestDataManager.getRandomUUID().toString());
		noticeData.setNoticeType("BKPAYRTN");
		noticeData.setNoticeUrl("noticeUrl");
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		noticeData.setOrderNo(trandno);
		cmbNotifyBean.setNoticeData(noticeData);

		return cmbNotifyBean;
	}

	/**
	 * ,支付网关招商签约回调
	 * 
	 * @param aqb
	 * @return
	 * @throws Exception
	 */
	public static CMBSignNotifyBean initCMBSignNotifyBean(AcquireOrderBean aqb)
			throws Exception {
		Logger.comment("初始化默认CMBSignNotifyBean,支付网关招商签约回调");
		CMBSignNotifyBean cmbSignNotifyBean = new CMBSignNotifyBean();
		cmbSignNotifyBean.setCharset("UTF-8");
		cmbSignNotifyBean.setSignType("RSA");
		cmbSignNotifyBean.setVersion("1.0");
		// NoticeData
		SNoticeData noticeData = new SNoticeData();
		noticeData.setBranchNo("0021");
		noticeData.setDateTime(YMTDateUtil.getSysTime("yyyyMMddHHmmss"));
		noticeData.setHttpMethod("POST");

		noticeData.setMerchantNo(CMB_SITMERID);
		noticeData
				.setNoticeSerialNo(TestDataManager.getRandomUUID().toString());
		noticeData.setNoticeType("BKQY");
		noticeData.setNoticeUrl("noticeUrl");
		String agrNo = new PayGateWayWapper()
				.selectCmbAggrementByUId(aqb.getUserId()).get(0).getId()
				.toString();
		noticeData.setAgrNo(agrNo);
		noticeData.setUserID(aqb.getUserId());
		noticeData.setNoPwdPay("N");
		noticeData.setNoticePara("Sign");
		noticeData.setUserPidType("1");
		noticeData.setUserPidHash(String.valueOf(aqb.getUserId().hashCode()));
		noticeData.setRspCode("SUC0000");
		noticeData.setRspMsg("autotest");
		cmbSignNotifyBean.setNoticeData(noticeData);

		return cmbSignNotifyBean;
	}

	/**
	 * 招行回调报文加签
	 * 
	 * @param noticeData
	 * @return
	 * @throws Exception
	 */
	public static String SignCMBNoticeData(NoticeData noticeData)
			throws Exception {
		PrivateKey privateKey = RSAUtils.loadPrivateKey(EnvSetup
				.getData("privateK"));
		TreeMap tm = new TreeMap();
		Map m1 = (Map) (FormatUtil.GSONToObject(
				FormatUtil.beanToGSONString(noticeData), Map.class));
		// Logger.debug("noticeData to map:"+m1);
		tm.putAll(m1);
		String fromatS = FormatUtil.mapToHttpString(tm, false);
		Logger.debug("sign src:" + fromatS);
		String signSWR = RSAUtils.SignSHA1WithRSA(fromatS, privateKey);
		Logger.debug("SignSHA1WithRSA:" + signSWR);
		return signSWR;
	}

	/**
	 * 招行回调实际报文
	 * 
	 * @param cMBNotifyBean
	 * @return
	 */
	public static String CMBNoticeSendString(Object cmbNotifyBean) {
		String send = "jsonRequestData=";
		send += FormatUtil
				.urlEncode(FormatUtil.beanToGSONString(cmbNotifyBean));
		return send;
	}

	public static AliPayWapCallBackBean initAliPayCallBackBean(
			AcquireOrderBean aqb) throws InterruptedException {
		Logger.comment("初始化默认AliPayNotifyBean,支付网关阿里回调");
		AliPayWapCallBackBean alicbBean = new AliPayWapCallBackBean();
		// trandno 是PaymentId
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		alicbBean.setOut_trade_no(trandno);
		alicbBean.setRequest_token("request_token");
		alicbBean.setResult("success");
		alicbBean.setTrade_no(TestDataManager.getRandomUUID().toString());
		return alicbBean;
	}

	/**
	 * 收单接口
	 * 
	 * @param acquireorderBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static AcquireOrderCall acquireOrder(
			AcquireOrderBean acquireorderBean) throws ClientProtocolException,
			IOException {
		Logger.comment("调用支付收单");
		String sign = new Sign().signMd5(acquireorderBean, Sign.autoTestKey);
		acquireorderBean.setSign(sign);
		AcquireOrderCall acquireorderCall = new AcquireOrderCall();
		acquireorderCall.setData(false, acquireorderBean);
		String type=acquireorderBean.getPayType();
		if(type.length()==4&&type.startsWith("10")){
			type=type.substring(2);
		}
		if(type.equals("4013")||type.equals("4016")) {
			//百度阿里支付用的商户号是 Alipay_MERID="2088701734809577";
			//百度的支付场景都用YMatouMERID
			PayGateWayCallService.initYMatouMERID();
		}
		if (type.equals("14")
				|| type.equals("15")
				|| type.equals("16")|| type.equals("6000")||type.equals("6001")||type.equals("6002")||type.equals("6003")||type.equals("4016")) {
			acquireorderCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			acquireorderCall.addHeader("MockResult-WeiXin-return_code",
					"SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-result_code",
					"SUCCESS");
			if (type.equals("16")||type.equals("4016")) {
				String qr = "weixin://pay//bizpayurl?pr=UsZ4kmA";
				acquireorderCall.addHeader("MockResult-WeiXin-code_url", qr);
			}
			Logger.comment("调用支付收单MOCKID" + mockid);
		}if(type.equals("17")){
			acquireorderCall.addHeader("Mock", "1");
			String mockid=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			acquireorderCall.addHeader("MockResult-WeiXin-return_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-result_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-appid", PayGateWayCallService.WX_AppID);
		}
		if(type.equals("18")){
			String mockid=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			acquireorderCall.addHeader("MockResult-WeiXin-return_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-result_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-appid", PayGateWayCallService.LiveShop_AppId);
			Logger.comment("Mock:1,MockResult-WeiXin-return_code:SUCCESS,MockResult-WeiXin-result_code:SUCCESS");
		}
		if(type.equals("3017")){
			acquireorderCall.addHeader("Mock", "1");
			String mockid=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			acquireorderCall.addHeader("MockResult-WeiXin-return_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-result_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-appid", PayGateWayCallService.WX_QQG_AppID);
		}if(type.equals("3015")){
			acquireorderCall.addHeader("Mock", "1");
			String mockid=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			acquireorderCall.addHeader("MockResult-WeiXin-return_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-result_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-appid", PayGateWayCallService.WX_QQG_AppID2);
		}if(type.equals("3117")){
			acquireorderCall.addHeader("Mock", "1");
			String mockid=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			acquireorderCall.addHeader("MockResult-WeiXin-return_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-result_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-appid", PayGateWayCallService.WX_QQG_AppID_Could_17);
		}if(type.equals("3115")){
			acquireorderCall.addHeader("Mock", "1");
			String mockid=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			acquireorderCall.addHeader("MockResult-WeiXin-return_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-result_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-appid", PayGateWayCallService.WX_QQG_AppID_Could_15);
		}if(type.equals("3215")){
			acquireorderCall.addHeader("Mock", "1");
			String mockid=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			acquireorderCall.addHeader("MockResult-WeiXin-return_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-result_code", "SUCCESS");
			acquireorderCall.addHeader("MockResult-WeiXin-appid", PayGateWayCallService.WX_QQG_AppID_Could_15_YDD);
		}if(type.equals("80")){
			acquireorderCall.addHeader("Mock", "1");
			String mockid=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
		}
		if (type.equals("6010")|| type.equals("6011")) { 
			acquireorderCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			String prePayId=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockResult-ShengPay-returnCode", "00");
			acquireorderCall.addHeader("MockResult-ShengPay-prepayId", prePayId);
			acquireorderCall.addHeader("MockResult-ShengPay-signType", "MD5");
		}
		if(type.equals("90")||type.equals("91")){
			acquireorderCall.addHeader("Mock", "1");
			String mockid=TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
		}
		if (type.equals("70")) {
			//nothing
		} 
		if (type.equals("62")|| type.equals("63")) { 
			//nothing
		}
		if (type.equals("60")|| type.equals("61")) { 
			acquireorderCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			acquireorderCall.addHeader("MockId", mockid);
			acquireorderCall.addHeader("MockResult-ApplePay-merId",
					PayGateWayCallService.APPLEPAY_MERID);
		}
		
		acquireorderCall.callService();
		Logger.comment("调用支付收单完成");
		return acquireorderCall;
	}

	/**
	 * 支付网关支付回调通知交易
	 * 
	 * @param type
	 * @param orderid
	 *            走第三方支付生成的交易号
	 * @param payprice
	 *            第三方支付金额
	 * @param userid
	 * @throws Exception
	 */
	public static void notifyCall(String type, String orderid, String payprice,
			long userid) throws Exception {
		notifyCall(type, orderid, payprice, userid, BigDecimal.ZERO);
	}
	
	/**
	 * 支付网关支付回调通知交易
	 * 
	 * @param type
	 * @param orderid
	 *            走第三方支付生成的交易号
	 * @param payprice
	 *            第三方支付金额
	 * @param userid
	 * @param discountAmount
	 * @throws Exception
	 */
	public static void notifyCall(String type, String orderid, String payprice,
			long userid, BigDecimal discountAmount) throws Exception {
		Logger.comment("第三方异步支付回调交易");
		AcquireOrderBean aqb = initAcquireOrder(type);
		if(type.equals("4013")||type.equals("4016")) {
			//百度阿里支付用的商户号是 Alipay_MERID="2088701734809577";
			PayGateWayCallService.initYMatouMERID();
		}
		aqb.setOrderId(orderid);
		aqb.setPayPrice(payprice);
		aqb.setUserId(String.valueOf(userid));
		aqb.setProductName("接口自动化测试Test");
		// 根据第三方交易号，查询支付收单trackid
		//		List<PPBussinessOrder> ppBussinessOrderList = new PayGateWayWapper().selectPPBussinessorderByOrderId(orderid);
		//		aqb.setTraceId(ppBussinessOrderList.get(0).getTraceId());
		NotifyCall notifyCall = new NotifyCall(aqb.getPayType());
		if(aqb.getPayType().length()==4&&aqb.getPayType().startsWith("10")){
			type=aqb.getPayType().substring(2);
			if(type.equals("09")){
				type="9";
			}
		}
		String send = "";
		if (type.equals("13") || type.equals("9")|| type.equals("3013")|| type.equals("3113")|| type.equals("3213")|| type.equals("8")|| type.equals("2013")|| type.equals("4013")) {
			AliPayNotifyBean alinotifyBean = initAliPayNotifyBean(aqb);
			if (type.equals("9")) {
				HbFq hb_fq_param = new HbFq();
				hb_fq_param.setHb_fq_num("3");
				hb_fq_param.setHb_fq_seller_percent("0");
				alinotifyBean.setHb_fq_param(hb_fq_param);
			}
			send = aliPayNotifyBeanToSend(alinotifyBean, aqb.getPayType());
		} else if (type.equals("14") || type.equals("15") || type.equals("17") || type.equals("18")|| type.equals("3017")|| type.equals("3015")) {
			WeiXinNotifyBean wxnotifyBean = initWeixinBean(aqb);
			
			if (discountAmount.compareTo(BigDecimal.ZERO) == 1) {
				
				String settle = new BigDecimal(aqb.getPayPrice())
				.subtract(discountAmount)
				.multiply(BigDecimal.valueOf(100)).setScale(0).toString();
				wxnotifyBean.setSettlement_total_fee(settle);
		
			}
			
			send = weiXinNotifyBeanToSend(wxnotifyBean);
		}
		// 招行
		else if (type.equals("50")) {
			CMBNotifyBean cmbNotifyBean = initCMBNotifyBean(aqb, "0");

			String sign = SignCMBNoticeData(cmbNotifyBean.getNoticeData());
			cmbNotifyBean.setSign(sign);
			send = PayGateWayCallService.CMBNoticeSendString(cmbNotifyBean);
		}
		// 宝付
		else if (type.equals("70")) {

			BaoFuNotifyBean baofu = PayGateWayCallService
					.initBaoFuNotifyBean(aqb);
			send = "data_content="
					+ new BaofooSignature().encryptData(FormatUtil
							.beanToGSONString(baofu));
		}
		else if (type.equals("80")) {
			BestPayNotifyBean BestPayNotifyBean = initBestPayNotifyBean(aqb);
			send = bestNotifyBeanToSend(BestPayNotifyBean);
		}
		else if (type.equals("6010")||type.equals("6011")) {
			SFTNotifyBean sftb = PayGateWayCallService.initSFTNotifyBean(aqb);
			send = PayGateWayCallService.SFTPayNotifyBeanToSend(sftb);
		}
		else if (type.equals("90")||type.equals("91")) {
			OrderNotifyBean ordernotifyBean = PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			OrderNotifyCall ordernotifyCall=new OrderNotifyCall();
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();	
			return;
		}
		else if (type.equals("6010")||type.equals("6011")) {
			SFTNotifyBean sftb = PayGateWayCallService.initSFTNotifyBean(aqb);
			send = PayGateWayCallService.SFTPayNotifyBeanToSend(sftb);
		}
		notifyCall.setData(send);
		notifyCall.addHeader("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		notifyCall.addHeader("MockId", mockid);
		Logger.comment("添加Mock:" + mockid);
		notifyCall.callService();
	}

	/**
	 * 招商银行支付回调通知交易
	 * 
	 * @param type
	 * @param orderid
	 *            走第三方支付生成的交易号
	 * @param payprice
	 *            第三方支付金额
	 * @param userid
	 * @return 招商银行平台的补贴金额
	 * @throws Exception
	 */
	public static void cmbNotifyCall(String orderid, String payprice,
			int userid, String discountAmount) throws Exception {
		Logger.comment("第三方异步支付回调交易");
		AcquireOrderBean aqb = initAcquireOrder("50");
		aqb.setOrderId(orderid);
		aqb.setPayPrice(payprice);
		aqb.setUserId(String.valueOf(userid));
		aqb.setProductName("接口自动化测试Test");
		// 根据第三方交易号，查询支付收单trackid
		//		List<PPBussinessOrder> ppBussinessOrderList = new PayGateWayWapper().selectPPBussinessorderByOrderId(orderid);
		//		aqb.setTraceId(ppBussinessOrderList.get(0).getTraceId());
		NotifyCall notifyCall = new NotifyCall("50");
		// 招商银行补贴金额随机
		//String discountAmount = String.valueOf((new Random().nextInt(10)));
		// String discountAmount=String.valueOf((8));
		CMBNotifyBean cmbNotifyBean = initCMBNotifyBean(aqb, discountAmount);

		String sign = SignCMBNoticeData(cmbNotifyBean.getNoticeData());
		cmbNotifyBean.setSign(sign);
		String send = PayGateWayCallService.CMBNoticeSendString(cmbNotifyBean);

		notifyCall.setData(send);
		notifyCall.addHeader("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		notifyCall.addHeader("MockId", mockid);
		Logger.comment("添加Mock:" + mockid);
		notifyCall.callService();
	}
	
	/**
	 * 代购神器支付回调通知交易
	 * 
	 * @param orderid
	 * @param payprice
	 * @param userid
	 * @param discountAmount
	 * @return
	 * @throws Exception
	 */
	public static BigDecimal DGSQNotifyCall(String orderid, String payprice,
			int userid, String discountAmount) throws Exception {
		return DGSQNotifyCall(orderid, payprice, userid, discountAmount, null, 6000);
	}
	
	/**
	 * 代购神器支付回调通知交易
	 * 
	 * @param orderid
	 * @param payprice
	 * @param userid
	 * @param discountAmount
	 * @param currency
	 * @return
	 * @throws Exception
	 */
	public static BigDecimal DGSQNotifyCall(String orderid, String payprice,
			int userid, String discountAmount, String currency) throws Exception {
		return DGSQNotifyCall(orderid, payprice, userid, discountAmount, currency, 6000);
	}
	
	/**
	 * 代购神器支付回调通知交易
	 * 
	 * @param orderid
	 * @param payprice
	 * @param userid
	 * @param discountAmount
	 * @param payChannel
	 * @return
	 * @throws Exception
	 */
	public static BigDecimal DGSQNotifyCall(String orderid, String payprice,
			int userid, String discountAmount, Integer payChannel) throws Exception {
		return DGSQNotifyCall(orderid, payprice, userid, discountAmount, null, payChannel);
	}
	
	/**
	 * 代购神器支付回调通知交易
	 * 
	 * @param orderid
	 * @param payprice
	 * @param userid
	 * @param discountAmount
	 * @param currency
	 * @param payChannel
	 * @return
	 * @throws Exception
	 */
	public static BigDecimal DGSQNotifyCall(String orderid, String payprice,
			int userid, String discountAmount, String currency, Integer payChannel) throws Exception {
		Logger.comment("第三方异步支付回调交易");
		AcquireOrderBean aqb = initAcquireOrder(payChannel.toString());
		
		BigDecimal orderRmb = BigDecimal.ZERO;
		
		if (currency == null)
			currency = "CNY";
		
		aqb.setSettleCurrency(currency);
		aqb.setPriceCurrency(currency);
		
		String send = "";
		aqb.setOrderId(orderid); 
		aqb.setPayPrice(payprice);
		aqb.setUserId(String.valueOf(userid));
		aqb.setProductName("接口自动化测试Test");
		
		if (aqb.getPayType().equalsIgnoreCase("6006")) {
			
			Logger.comment("支付宝渠道");
			
			HipoPayNotifyCall hipoPayNotifyCall = new HipoPayNotifyCall();
			HipoNotifyBean hipoNotifyBean = initHipoNotifyBean(aqb,
					currency.equalsIgnoreCase("CNY") == false ? "1"
							: PayGateWayCallService.HKExchangeRate);
			
			orderRmb = new BigDecimal(aqb.getPayPrice()).divide(
					new BigDecimal(currency.equalsIgnoreCase("CNY") == true ? "1"
							: PayGateWayCallService.HKExchangeRate), 2,
					BigDecimal.ROUND_DOWN);
			
			// 计价单位
			hipoNotifyBean.setSettle_currency(aqb.getSettleCurrency());
			hipoNotifyBean.setCurrency(currency);
//			hipoNotifyBean.setExchange_rate("1");
			send = FormatUtil.beanToHttpString(hipoNotifyBean, true);
			hipoPayNotifyCall.setData(send);
			hipoPayNotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			hipoPayNotifyCall.addHeader("MockId", mockid);
			Logger.comment("添加Mock:" + mockid);
			hipoPayNotifyCall.callService();
			
		} else if (aqb.getPayType().equalsIgnoreCase("6010") ||  aqb.getPayType().equalsIgnoreCase("6011")) {
			
			HipoPayNotifyCall hipoPayNotifyCall = new HipoPayNotifyCall();
			HipoNotifyBean hipoNotifyBean = initHipoNotifyBean(aqb,
					"1");
			hipoNotifyBean.setCurrency(currency);
			
			orderRmb = new BigDecimal(aqb.getPayPrice()).divide(
					new BigDecimal("1"), 2,
					BigDecimal.ROUND_DOWN);
			
			hipoNotifyBean.setPay_amount(orderRmb.toString());
			hipoNotifyBean.setPay_currency(currency);
			
			send = FormatUtil.beanToHttpString(hipoNotifyBean, true);
			hipoPayNotifyCall.setData(send);
			hipoPayNotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			hipoPayNotifyCall.addHeader("MockId", mockid);
			Logger.comment("添加Mock:" + mockid);
			hipoPayNotifyCall.callService();
			
		} else {
			
			HipoPayNotifyCall hipoPayNotifyCall = new HipoPayNotifyCall();
			HipoNotifyBean hipoNotifyBean = initHipoNotifyBean(aqb,
					currency.equalsIgnoreCase("CNY") == false ? "1"
							: PayGateWayCallService.HKExchangeRate);
			hipoNotifyBean.setCurrency(currency);
			
			orderRmb = new BigDecimal(aqb.getPayPrice()).divide(
					new BigDecimal(currency.equalsIgnoreCase("CNY") == true ? "1"
							: PayGateWayCallService.HKExchangeRate), 2,
					BigDecimal.ROUND_DOWN);
			
			hipoNotifyBean.setPay_amount(orderRmb.toString());
			hipoNotifyBean.setPay_currency(currency);
			
			send = FormatUtil.beanToHttpString(hipoNotifyBean, true);
			hipoPayNotifyCall.setData(send);
			hipoPayNotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			hipoPayNotifyCall.addHeader("MockId", mockid);
			Logger.comment("添加Mock:" + mockid);
			hipoPayNotifyCall.callService();
		}

		return orderRmb;
	}
	
	/**
	 * 只支持hipopay，当标价币种和结算币种不一致时，代购神器支付回调通知交易
	 * 
	 * @return
	 * @throws Exception
	 */
	public static BigDecimal DGSQNotifyCall(String orderid, String payprice,
			int userid, String discountAmount, String priceCurrency, String settleCurrency) throws Exception {
		Logger.comment("第三方异步支付回调交易");
		AcquireOrderBean aqb = initAcquireOrder("6000");

		BigDecimal orderRmb = BigDecimal.ZERO;
		String exchangeRate = null;

		aqb.setSettleCurrency(settleCurrency);
		aqb.setPriceCurrency(priceCurrency);
		
		if (priceCurrency.equalsIgnoreCase(settleCurrency)) {
			exchangeRate = "1";
		} else {
			// 根据人民币离岸汇率计算
			exchangeRate = DGSQBaseService.getCurrencyConfig(settleCurrency)
					.getExchangeRmbRate().setScale(5, BigDecimal.ROUND_DOWN).toPlainString();
		}

		String send = "";
		aqb.setOrderId(orderid);
		aqb.setPayPrice(payprice);
		aqb.setUserId(String.valueOf(userid));
		aqb.setProductName("接口自动化测试Test");

		HipoPayNotifyCall hipoPayNotifyCall = new HipoPayNotifyCall();
		HipoNotifyBean hipoNotifyBean = initHipoNotifyBean(aqb,
				exchangeRate);
		hipoNotifyBean.setCurrency(priceCurrency);
		
		orderRmb = priceCurrency.equalsIgnoreCase(settleCurrency) ? new BigDecimal(
				payprice).multiply(
				DGSQBaseService.getCurrencyConfig(settleCurrency)
						.getExchangeRmbRate()).setScale(2,
				BigDecimal.ROUND_HALF_DOWN) : new BigDecimal(payprice);

		hipoNotifyBean.setPay_amount(orderRmb.toString());
		hipoNotifyBean.setPay_currency(priceCurrency);

		send = FormatUtil.beanToHttpString(hipoNotifyBean, true);
		hipoPayNotifyCall.setData(send);
		hipoPayNotifyCall.addHeader("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		hipoPayNotifyCall.addHeader("MockId", mockid);
		Logger.comment("添加Mock:" + mockid);
		hipoPayNotifyCall.callService();

		return orderRmb;
	}

	/**
	 * 支付网关退款回调通知交易
	 * 
	 * @param type
	 * @param orderid
	 * @param userid
	 * @throws Exception
	 */
	public static void refundNotifyCall(String payType, String thirdTradingId,
			long userId) throws Exception {
		Logger.comment("第三方异步退款回调交易");

		refundNotifyCall(payType, thirdTradingId, userId, BigDecimal.ZERO);

	}
	
	/**
	 * 支付网关退款回调通知交易
	 * 
	 * @param type
	 * @param orderid
	 * @param userid
	 * @throws Exception
	 */
	public static void refundNotifyCall(String payType, String thirdTradingId,
			long userId, BigDecimal discountAmount) throws Exception {
		Logger.comment("第三方异步退款回调交易");

		AcquireOrderBean aqb = initAcquireOrder(payType);

		// 查询申请退款的 RefundRequest 表
		List<MRefund> refundRequestList = null;
		for (int i = 0; i < 10; i++) {

			refundRequestList = new PayGateWayWapper()
					.selectRefundRequestByTradeNo(thirdTradingId);
			if (!CollectionUtils.isEmpty(refundRequestList)) {
				break;
			}
			Thread.sleep(1000);
		}

		if (CollectionUtils.isEmpty(refundRequestList)) {

			Logger.info(String.format(
					"############ 超过10s,支付网关未查到退款单 tradeNo : %s",
					thirdTradingId));

			return;
		}

		BigDecimal totalRefun = refundRequestList.stream()
				.map(refund -> refund.getRefundAmt())
				.reduce(BigDecimal.ZERO, BigDecimal::add);

		List<String> refundIdList = new ArrayList<String>();

		refundRequestList.forEach(r ->

		refundIdList.add(String.valueOf(r.getRefundId())));

		aqb.setOrderId(thirdTradingId);
		aqb.setPayPrice(totalRefun.toString());
		aqb.setUserId(String.valueOf(userId));
		aqb.setProductName("接口自动化测试Test");

		// 退款审核通过 根据第三方交易号，审核所有退款单
		approveRefundByRefundIds(refundIdList);

		//审核之后在查一次
		refundRequestList = new PayGateWayWapper()
				.selectRefundRequestByTradeNo(thirdTradingId);

		// 审核通过后生成 RefundBatchNo
		for (MRefund refundRequest : refundRequestList) {
			// 退款审核通过后执行退款
			/*	executeRefund(refundRequest, payType, false);

				String send = null;

				// 只有支付宝渠道才有退款通知，微信 没有
				if (payType.equals("10") || payType.equals("13")
						|| payType.equals("9")) {
					// 构造通知bean数据
					RefundNotifyBean refundnotifyBean = initRefundNotifyBean(refundRequest);
					// 排序加签名
					String src = FormatUtil.beanToHttpString(refundnotifyBean,
							false);
					String sign = new Sign().SignSHA1WithRSA(src);
					refundnotifyBean.setSign(sign);
					refundnotifyBean.setSign_type("RSA");
					// 转换成最终发出的数据
					send = FormatUtil.beanToHttpString(refundnotifyBean, true);

				} else if (payType.equals("60")) {
					ApplePayRefundNotifyBean applerfb = initApplePayRefundNotifyBean(aqb);
					// 排序加签名
					send = ApplePayRefundNotifyToSend(applerfb, aqb);
					// 宝付支付的 退款回调
				} else if (payType.equals("70")) {

					send = FormatUtil.beanToGSONString(PayGateWayCallService
							.initBaoFuRefundNotifyBean(aqb));
					Logger.debug("baofuexecfund:" + send);

					send = "data_content="
							+ new BaofooSignature().encryptData(send);

				}*/

			// 转换成最终发出的数据
			//			RefundNotifyCall refundnotifyCall = new RefundNotifyCall();
			//			refundnotifyCall = new RefundNotifyCall(payType);
			//			refundnotifyCall.setData(send);
			//			refundnotifyCall.addHeader("Mock", "1");
			//			String mockid = TestDataManager.getRandomUUID().toString();
			//			refundnotifyCall.addHeader("MockId", mockid);
			//			refundnotifyCall.callService();
			
			new PayGateWayWapper().updateRefundStatus(
					refundRequest.getRefundBatchNo(), "3");
			
			if (discountAmount.compareTo(BigDecimal.ZERO) == 1) {
				new PayGateWayWapper().updateRefundRefundDiscountAmt(
						refundRequest.getRefundBatchNo(), discountAmount.setScale(2));
			}
			
			executeRefund(refundRequest.getRefundId().toString());
		}
	}
	
	/**
	 * 退款执行
	 * 
	 * @param refundRequest
	 * @param payType
	 */
	public static void executeRefund(MRefund refundRequest, String payType) {
		Logger.comment("执行退款执行");

		ExecuteRefundBean executerefundBean = new ExecuteRefundBean();
		ExecuteRefundCall executerefundCall = new ExecuteRefundCall();
		try {
			String refundbn = refundRequest.getRefundBatchNo();
			String refundid = refundRequest.getRefundId().toString();
			// 更新退款状态
			new PayGateWayWapper().updateRefundStatus(refundbn, "1");
			executerefundBean.setRefundId(refundid);
			executerefundCall.setData(executerefundBean);
			executerefundCall.addHeader("Mock", "1");
			// 13 为 app国际支付宝，15 微信
			String InstPaymentId = new PayGateWayWapper()
					.selectPPPaymentByPaymentId(refundRequest.getPaymentId())
					.get(0).getInstitutionPaymentId();
			if (payType.equals("10") || payType.equals("13") || payType.equals("3013")||payType.equals("3113")||payType.equals("3213")|| payType.equals("2013") 
					|| payType.equals("9")|| payType.equals("8")|| payType.equals("4013")) {
				String mockResult = FormatUtil
						.urlEncode("is_success=T&result_details=" + refundbn
								+ "^" + InstPaymentId + "^"
								+ refundRequest.getRefundAmt().setScale(2)
								+ "^SUCCESS");
				executerefundCall.addHeader("MockResult-AliPay-Result",
						mockResult);
			} else if (payType.equals("14") || payType.equals("15")) {
				executerefundCall.addHeader("MockResult-WeiXin-refund_status",
						"SUCCESS");
				executerefundCall.addHeader(
						"MockResult-WeiXin-refund_fee",
						String.valueOf(refundRequest.getRefundAmt().setScale(2)
								.multiply(new BigDecimal(100)).intValue()));
			} else if (payType.equals("50")) {
				// 更新退款状态为 3
				new PayGateWayWapper().updateRefundStatus(refundbn, "3");
				// executerefundCall.addHeader("MockResult-Cmb-rspCode","SUC0000");
				// executerefundCall.addHeader("MockResult-Cmb-cardType","02");
				// executerefundCall.addHeader("MockResult-Cmb-orderAmount",refundRequest.getRefundAmount().toString());
				// executerefundCall.addHeader("MockResult-Cmb-discountAmount","0.00");
				// executerefundCall.addHeader("MockResult-Cmb-orderStatus","0");
				// executerefundCall.addHeader("MockResult-Cmb-date",YMTDateUtil.getSysTime("yyyyMMdd"));
				// executerefundCall.addHeader("MockResult-Cmb-orderNo",refundRequest.getPaymentId());
			}

			else if (payType.equals("70")) {
				// 更新退款状态为 3
				new PayGateWayWapper().updateRefundStatus(refundbn, "3");

			}
			else if (payType.equals("90")||payType.equals("91")) {
				Map mock=getFQLRefundMock(refundRequest.getRefundAmt().setScale(2).toString(),refundbn);
				PayGateWayCallService.addMock(executerefundCall, mock);
				executerefundCall.callService();
				return;
			}
			String mockid = TestDataManager.getRandomUUID().toString();
			executerefundCall.addHeader("MockId", mockid);
			executerefundCall.callService();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	private static Map getFQLRefundMock(String refundamt,String refundbn) {
		Logger.comment("获取默认的Mock信息");
		Map m = new HashMap<String, String>();
		m.put("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		m.put("MockId", mockid);
//		MockResult-FqlPay-result: 0
		m.put("MockResult-FqlPay-result", 0);
//		MockResult-FqlPay-refund_state:   10退款中20退款成功30退款失败40已结算冲销
		m.put("MockResult-FqlPay-refund_state", 20);
//		MockResult-FqlPay-amount: 退款金额
		m.put("MockResult-FqlPay-amount", refundamt);
//		MockResult-FqlPay-refund_id: fql-refunid 分期乐退款单号
		m.put("MockResult-FqlPay-refund_id", TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
//		MockResult-FqlPay-third_refund_id: ymt-refundId 洋码头退款单号 String refundbn = mrr.getRefundBatchNo().toString();
		m.put("MockResult-FqlPay-third_refund_id", refundbn);
		return m;
	}
	/**
	 * 正常的退款执行 会执行的真实账户
	 * @param refundid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void executeRefund(String refundid)
			throws ClientProtocolException, IOException {
		Logger.comment("执行退款执行");
		ExecuteRefundBean executerefundBean = new ExecuteRefundBean();
		ExecuteRefundCall executerefundCall = new ExecuteRefundCall();
		executerefundBean.setRefundId(refundid);
		executerefundCall.setData(false, executerefundBean);
		executerefundCall.callService();

	}
	/**
	 * 指定回调交易mock是否成功
	 * @param refundRequest
	 * @param payType
	 * @param tradingSuccess
	 */
	public static void executeRefund(MRefund refundRequest, String payType,
			boolean tradingSuccess) {
		Logger.comment("执行退款执行");
		ExecuteRefundBean executerefundBean = new ExecuteRefundBean();
		ExecuteRefundCall executerefundCall = new ExecuteRefundCall();
		//call mockforpay.iapi.ymatou.com/warmup 预热
		callWarmup();

		try {
			String refundbn = refundRequest.getRefundBatchNo();
			String refundid = refundRequest.getRefundId().toString();
			// 更新退款状态
			new PayGateWayWapper().updateRefundStatus(refundbn, "1");
			executerefundBean.setRefundId(refundid);
			executerefundCall.setData(false, executerefundBean);
			executerefundCall.addHeader("Mock", "1");
			// 13 为 app国际支付宝，15 微信
			String InstPaymentId = new PayGateWayWapper()
					.selectPPPaymentByPaymentId(refundRequest.getPaymentId())
					.get(0).getInstitutionPaymentId();
			if (payType.equals("10") || payType.equals("13") || payType.equals("3013")|| payType.equals("3113")|| payType.equals("3213")|| payType.equals("2013")
					|| payType.equals("9")|| payType.equals("8")|| payType.equals("4013")) {
				String mockResult = FormatUtil
						.urlEncode("is_success=T&result_details=" + refundbn
								+ "^" + InstPaymentId + "^"
								+ refundRequest.getRefundAmt().setScale(2)
								+ "^SUCCESS");
				executerefundCall.addHeader("MockResult-AliPay-Result",
						mockResult);
			} else if (payType.equals("14") || payType.equals("15")) {
				executerefundCall.addHeader("MockResult-WeiXin-refund_status",
						"SUCCESS");
				executerefundCall.addHeader(
						"MockResult-WeiXin-refund_fee",
						String.valueOf(refundRequest.getRefundAmt().setScale(2)
								.multiply(new BigDecimal(100)).intValue()));
			} else if (payType.equals("50")) {
				// 更新退款状态为 3
				new PayGateWayWapper().updateRefundStatus(refundbn, "3");
				// executerefundCall.addHeader("MockResult-Cmb-rspCode","SUC0000");
				// executerefundCall.addHeader("MockResult-Cmb-cardType","02");
				// executerefundCall.addHeader("MockResult-Cmb-orderAmount",refundRequest.getRefundAmount().toString());
				// executerefundCall.addHeader("MockResult-Cmb-discountAmount","0.00");
				// executerefundCall.addHeader("MockResult-Cmb-orderStatus","0");
				// executerefundCall.addHeader("MockResult-Cmb-date",YMTDateUtil.getSysTime("yyyyMMdd"));
				// executerefundCall.addHeader("MockResult-Cmb-orderNo",refundRequest.getPaymentId());
			}

			else if (payType.equals("70")) {
				// 更新退款状态为 3
				new PayGateWayWapper().updateRefundStatus(refundbn, "3");

			}

			String mockid = TestDataManager.getRandomUUID().toString();
			executerefundCall.addHeader("MockId", mockid);
			if (tradingSuccess) {
				executerefundCall.addHeader("MockResult-Trading-Status", "OK");
			} else {
				executerefundCall.addHeader("MockResult-Trading-Status",
						"FAILD");
			}

			executerefundCall.callService();

		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	/**
	 * 第三方异步回调支付
	 * 目前用于微信立减
	 * @param aqb
	 * @param discountAmonunt 立减金额 1.00代表1元
	 * @throws Exception
	 */
	public static void notifyCall(AcquireOrderBean aqb ,String discountAmt) throws Exception {
		Logger.comment("第三方异步回调支付");
		aqb.setProductName("接口自动化测试Test");
		NotifyCall notifyCall = new NotifyCall(aqb.getPayType());
		String send = "";
		String type=aqb.getPayType();
		if(aqb.getPayType().length()==4&&aqb.getPayType().startsWith("10")){
			type=aqb.getPayType().substring(2);
			if(type.equals("09")){
				type="9";
			}
		}
		if (type.equals("10") || type.equals("13") || type.equals("3013")|| type.equals("3113")|| type.equals("3213")|| type.equals("2013") 
				|| type.equals("9")|| type.equals("8")|| type.equals("4013")) {
			AliPayNotifyBean alinotifyBean = initAliPayNotifyBean(aqb);
			send = aliPayNotifyBeanToSend(alinotifyBean, aqb.getPayType());
		} else if (type.equals("14")
				|| type.equals("15")
				|| type.equals("16")||type.equals("4016")
				|| type.equals("17") || type.equals("18")|| type.equals("19")|| type.equals("3017")|| type.equals("3015") ) {
			WeiXinNotifyBean wxnotifyBean = initWeixinBean(aqb);
			//settle 实际用户付款=（原价-立减） *100 单位分
			String settle=new BigDecimal(aqb.getPayPrice()).subtract(new BigDecimal(discountAmt)).multiply(BigDecimal.valueOf(100)).setScale(0).toString();
			wxnotifyBean.setSettlement_total_fee(settle);
			send = weiXinNotifyBeanToSend(wxnotifyBean);
		} else if (type.equals("11")) {
			AliPayWapNotifyBean aliwap = PayGateWayCallService
					.initAliPayWapNotify(aqb);
			send = PayGateWayCallService.signAliWapNotify(aliwap);
		} else if (type.equals("60")
				|| type.equals("61")) {
			ApplePayNotifyBean apple = PayGateWayCallService
					.initApplePayNotifyBean(aqb);
			send = PayGateWayCallService.signApplePayNotify(apple);
		} else if (type.equals("62")
				|| type.equals("63")) {
			ApplePayNotifyBean apple = PayGateWayCallService
					.initApplePayNotifyBean(aqb);
			apple.setMerId(UPAY_MERID);
			send = PayGateWayCallService.signApplePayNotify(apple);
		}
		else if (type.equals("64")|| type.equals("65")|| type.equals("66")) {
			ApplePayNotifyBean apple = PayGateWayCallService
					.initApplePayNotifyBean(aqb);
			apple.setMerId(UPAY_MERID);
			send = PayGateWayCallService.signApplePayNotify(apple);
		}else if (type.equals("50")) {
			NotifyCall50 notifyCall50 = new NotifyCall50();
			CMBNotifyBean cmbNotifyBean = PayGateWayCallService
					.initCMBNotifyBean(aqb, "0");
			String sign = PayGateWayCallService.SignCMBNoticeData(cmbNotifyBean
					.getNoticeData());
			cmbNotifyBean.setSign(sign);
			send = PayGateWayCallService.CMBNoticeSendString(cmbNotifyBean);
			notifyCall50.setData(send);
			notifyCall50.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			notifyCall50.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);
			notifyCall50.callService();
			return;
		} else if (type.equals("70")) {
			BaoFuNotifyBean baofu = PayGateWayCallService
					.initBaoFuNotifyBean(aqb);
			send = "data_content="
					+ new BaofooSignature().encryptData(FormatUtil
							.beanToGSONString(baofu));
			NotifyCall70 notifyCall70 = new NotifyCall70();
			notifyCall70.setData(send);
			notifyCall70.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			notifyCall70.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);
			notifyCall70.callService();
			return;
		}
		else if (type.equals("80")) {
			BestPayNotifyBean BestPayNotifyBean = initBestPayNotifyBean(aqb);
			send = bestNotifyBeanToSend(BestPayNotifyBean);
		}
		else if (type.equals("6010")||type.equals("6011")) {
			SFTNotifyBean sftb = PayGateWayCallService.initSFTNotifyBean(aqb);
			send = PayGateWayCallService.SFTPayNotifyBeanToSend(sftb);
		}
		else if (type.equals("90")||type.equals("91")) {
			OrderNotifyBean ordernotifyBean = PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			OrderNotifyCall ordernotifyCall=new OrderNotifyCall();
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();	
			return;
		}
		notifyCall.setData(send);
		notifyCall.addHeader("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		notifyCall.addHeader("MockId", mockid);
		Logger.comment("添加Mock:" + mockid);
		notifyCall.callService();
	}
	public static void notifyCall(AcquireOrderBean aqb) throws Exception {
		notifyCallToMock(aqb,TestDataManager.getRandomUUID().toString());
	}
	public static void notifyCallToMock(AcquireOrderBean aqb,String mockid) throws Exception {
		Logger.comment("第三方异步回调支付");
		aqb.setProductName("接口自动化测试Test");
		NotifyCall notifyCall = new NotifyCall(aqb.getPayType());
		if(aqb.getPayType().equals("2013")) {
			notifyCall = new NotifyCall("13");
		}
		String send = "";
		String type=aqb.getPayType();
		if(aqb.getPayType().length()==4&&aqb.getPayType().startsWith("10")){
			type=aqb.getPayType().substring(2);
			if(type.equals("09")){
				type="9";
			}
		}
		if (type.equals("10") || type.equals("13") || type.equals("3013")|| type.equals("3113")|| type.equals("3213")|| type.equals("2013") 
				|| type.equals("9")|| type.equals("8")|| type.equals("4013")) {
			AliPayNotifyBean alinotifyBean = initAliPayNotifyBean(aqb);
			send = aliPayNotifyBeanToSend(alinotifyBean, aqb.getPayType());
		} else if (type.equals("14")
				|| type.equals("15")
				|| type.equals("16")||type.equals("4016")
				|| type.equals("17") || type.equals("18")|| type.equals("19")|| type.equals("3017")|| type.equals("3015") || type.equals("3117")|| type.equals("3115")|| type.equals("3215")) {
			WeiXinNotifyBean wxnotifyBean = initWeixinBean(aqb);
			send = weiXinNotifyBeanToSend(wxnotifyBean);
		} else if (type.equals("11")) {
			AliPayWapNotifyBean aliwap = PayGateWayCallService
					.initAliPayWapNotify(aqb);
			send = PayGateWayCallService.signAliWapNotify(aliwap);
		} else if (type.equals("60")
				|| type.equals("61")) {
			ApplePayNotifyBean apple = PayGateWayCallService
					.initApplePayNotifyBean(aqb);
			send = PayGateWayCallService.signApplePayNotify(apple);
		} else if (type.equals("62")
				|| type.equals("63")) {
			ApplePayNotifyBean apple = PayGateWayCallService
					.initApplePayNotifyBean(aqb);
			apple.setMerId(UPAY_MERID);
			send = PayGateWayCallService.signApplePayNotify(apple);
		}
		else if (type.equals("64")|| type.equals("65")|| type.equals("66")) {
			ApplePayNotifyBean apple = PayGateWayCallService
					.initApplePayNotifyBean(aqb);
			apple.setMerId(UPAY_MERID);
			send = PayGateWayCallService.signApplePayNotify(apple);
		}else if (type.equals("50")) {
			NotifyCall50 notifyCall50 = new NotifyCall50();
			CMBNotifyBean cmbNotifyBean = PayGateWayCallService
					.initCMBNotifyBean(aqb, "0");
			String sign = PayGateWayCallService.SignCMBNoticeData(cmbNotifyBean
					.getNoticeData());
			cmbNotifyBean.setSign(sign);
			send = PayGateWayCallService.CMBNoticeSendString(cmbNotifyBean);
			notifyCall50.setData(send);
			notifyCall50.addHeader("Mock", "1");
			notifyCall50.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);
			notifyCall50.callService();
			return;
		} else if (type.equals("70")) {
			BaoFuNotifyBean baofu = PayGateWayCallService
					.initBaoFuNotifyBean(aqb);
			send = "data_content="
					+ new BaofooSignature().encryptData(FormatUtil
							.beanToGSONString(baofu));
			NotifyCall70 notifyCall70 = new NotifyCall70();
			notifyCall70.setData(send);
			notifyCall70.addHeader("Mock", "1");
			notifyCall70.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);
			notifyCall70.callService();
			return;
		}
		else if (type.equals("80")) {
			BestPayNotifyBean BestPayNotifyBean = initBestPayNotifyBean(aqb);
			send = bestNotifyBeanToSend(BestPayNotifyBean);
		}
		else if (type.equals("6010")||type.equals("6011")) {
			SFTNotifyBean sftb = PayGateWayCallService.initSFTNotifyBean(aqb);
			send = PayGateWayCallService.SFTPayNotifyBeanToSend(sftb);
		}
		else if (type.equals("90")||type.equals("91")) {
			OrderNotifyBean ordernotifyBean = PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			OrderNotifyCall ordernotifyCall=new OrderNotifyCall();
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();	
			return;
		}
		else if (type.equals("6000")) {
			HipoPayNotifyCall hipoPayNotifyCall=new HipoPayNotifyCall();
			HipoNotifyBean hipoNotifyBean = initHipoNotifyBean(aqb,PayGateWayCallService.HKExchangeRate);
			//计价单位
			hipoNotifyBean.setSettle_currency(aqb.getSettleCurrency());
			hipoNotifyBean.setCurrency(aqb.getPriceCurrency());
			hipoNotifyBean.setExchange_rate("1");
			send = FormatUtil.beanToHttpString(hipoNotifyBean, true);
			hipoPayNotifyCall.setData(send);
			hipoPayNotifyCall.addHeader("Mock", "1");
			hipoPayNotifyCall.addHeader("MockId", mockid);
			Logger.comment("添加Mock:" + mockid);
			hipoPayNotifyCall.callService();
			return;
		}
		else if (type.equals("6103")||type.equals("6107")) {
			HipoPayNotifyCall hipoPayNotifyCall=new HipoPayNotifyCall("hipoPayNotify/"+type);
			HipoNotifyBean hipoNotifyBean = initHipoNotifyBean(aqb,PayGateWayCallService.HKExchangeRate);
			//计价单位
			hipoNotifyBean.setSettle_currency(aqb.getSettleCurrency());
			hipoNotifyBean.setCurrency(aqb.getPriceCurrency());
			hipoNotifyBean.setExchange_rate("1");
			send = FormatUtil.beanToHttpString(hipoNotifyBean, true);
			hipoPayNotifyCall.setData(send);
			hipoPayNotifyCall.addHeader("Mock", "1");
			hipoPayNotifyCall.addHeader("MockId", mockid);
			Logger.comment("添加Mock:" + mockid);
			hipoPayNotifyCall.callService();
			return;
		}
		else if (type.equals("6001")||type.equals("6001")||type.equals("6002")||type.equals("6003")) {
			HipoPayNotifyH5Call hipoPayNotifyCall=new HipoPayNotifyH5Call();
			HipoNotifyH5Bean hipoNotifyBean = initHipoH5NotifyBean(aqb,PayGateWayCallService.HKExchangeRate);
			//计价单位
			hipoNotifyBean.setCurrency(aqb.getPriceCurrency());
			hipoNotifyBean.setExchange_rate("1");
			send = FormatUtil.beanToHttpString(hipoNotifyBean, true);
			hipoPayNotifyCall.setData(send);
			hipoPayNotifyCall.addHeader("Mock", "1");
			hipoPayNotifyCall.addHeader("MockId", mockid);
			Logger.comment("添加Mock:" + mockid);
			hipoPayNotifyCall.callService();
			return;
		} 
		else if (type.equals("6006")) {
			HipoPayNotifyCall hipoPayNotifyCall=new HipoPayNotifyCall();
			HipoNotifyBean hipoNotifyBean = initHipoNotifyBean(aqb,PayGateWayCallService.HKExchangeRate);
			//计价单位
			hipoNotifyBean.setSettle_currency(aqb.getSettleCurrency());
			hipoNotifyBean.setCurrency(aqb.getPriceCurrency());
			hipoNotifyBean.setExchange_rate("1");
			send = FormatUtil.beanToHttpString(hipoNotifyBean, true);
			hipoPayNotifyCall.setData(send);
			hipoPayNotifyCall.addHeader("Mock", "1");
			hipoPayNotifyCall.addHeader("MockId", mockid);
			Logger.comment("添加Mock:" + mockid);
			hipoPayNotifyCall.callService();
			return;
		}
		else if (type.equals("6100")) {
			AliPayNotifyBean alinotifyBean = initAliPayNotifyBean(aqb);
			alinotifyBean.setSeller_email(PayGateWayCallService.GODAliPay_EMAIL);
			alinotifyBean.setSeller_id(PayGateWayCallService.GODAliPay_MERID);
			send = aliPayNotifyBeanToSend(alinotifyBean, aqb.getPayType());
		} 
		notifyCall.setData(send);
		notifyCall.addHeader("Mock", "1");
		notifyCall.addHeader("MockId", mockid);
		Logger.comment("添加Mock:" + mockid);
		notifyCall.callService();
	}

	/**
	 * 招行专用支付回调 可以设置优惠金额
	 * 
	 * @param aqb
	 * @param discountAmonunt
	 * @throws Exception
	 */
	public static void notifyCall50(AcquireOrderBean aqb, String discountAmonunt)
			throws Exception {
		Logger.comment("第三方异步回调支付");
		aqb.setProductName("接口自动化测试Test");
		NotifyCall notifyCall = new NotifyCall(aqb.getPayType());
		String send = "";
		NotifyCall50 notifyCall50 = new NotifyCall50();
		CMBNotifyBean cmbNotifyBean = PayGateWayCallService.initCMBNotifyBean(
				aqb, discountAmonunt);
		String sign = PayGateWayCallService.SignCMBNoticeData(cmbNotifyBean
				.getNoticeData());
		cmbNotifyBean.setSign(sign);
		send = PayGateWayCallService.CMBNoticeSendString(cmbNotifyBean);
		notifyCall50.setData(send);
		notifyCall50.addHeader("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		notifyCall50.addHeader("MockId", mockid);
		Logger.comment("添加Mock:" + mockid);
		notifyCall50.callService();
	}

	/**
	 * 申请退款
	 * 
	 * @param aqb
	 * @return
	 * @throws Exception
	 */
	public static SubmitRefundBean submitRefund(AcquireOrderBean aqb)
			throws Exception {
		Logger.comment("申请退款");
		SubmitRefundBean submitrefundBean = new SubmitRefundBean();
		SubmitRefundCall submitrefundCall = new SubmitRefundCall();
		submitrefundBean.setAppId("AutoTest");
		submitrefundBean.setOrderId(TestDataManager.getRandomNum(12));
		submitrefundBean.setTraceId(TestDataManager.getRandomUUID().toString()
				.replace("-", ""));
		List<TradeDetail> TradeDetails = new ArrayList<TradeDetail>();
		TradeDetail td = new TradeDetail();
		td.setTradeNo(aqb.getOrderId());
		td.setTradeType("2");
		TradeDetails.add(td);
		submitrefundBean.setTradeDetails(TradeDetails);
		String sign = new Sign().signMd5(submitrefundBean, Sign.autoTestKey);
		submitrefundBean.setSign(sign);
		submitrefundCall.setData(false, submitrefundBean);
		submitrefundCall.callService();
		return submitrefundBean;
	}

	/**
	 * 新版java版申请退款
	 * 
	 * @param aqb
	 * @return
	 * @throws Exception
	 */
	public static SubmitRefundBean JSubmitRefund(AcquireOrderBean aqb)
			throws Exception {
		Logger.comment("申请退款");
		SubmitRefundBean submitrefundBean = new SubmitRefundBean();
		com.ymatou.iapi.payment.service.SubmitRefundCall submitrefundCall = new com.ymatou.iapi.payment.service.SubmitRefundCall();
		submitrefundBean.setAppId("AutoTest");
		submitrefundBean.setOrderId(TestDataManager.getRandomNum(12));
		submitrefundBean.setTraceId(TestDataManager.getRandomUUID().toString()
				.replace("-", ""));
		List<TradeDetail> TradeDetails = new ArrayList<TradeDetail>();
		TradeDetail td = new TradeDetail();
		td.setTradeNo(aqb.getOrderId());
		td.setTradeType("2");
		TradeDetails.add(td);
		submitrefundBean.setTradeDetails(TradeDetails);
		String sign = new Sign().signMd5(submitrefundBean, Sign.autoTestKey);
		submitrefundBean.setSign(sign);
		submitrefundCall.setData(false, submitrefundBean);
		submitrefundCall.callService();
		return submitrefundBean;
	}

	/**
	 * 申请部分退款
	 * 
	 * @param aqb
	 * @return
	 * @throws Exception
	 */
	public static AcquireRefundBean AcquireRefund(AcquireOrderBean aqb,
			String refundAmt) throws Exception {
		Logger.comment("申请部分退款");
		AcquireRefundBean acquirerefundBean = new AcquireRefundBean();
		AcquireRefundCall acquirerefundCall = new AcquireRefundCall();
		acquirerefundBean.setAppId("AutoTest");
		acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
		acquirerefundBean.setRefundAmt(refundAmt);
		acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
		acquirerefundBean.setTradeNo(aqb.getOrderId());
		acquirerefundBean.setBizNo(TestDataManager.getRandomUUID().toString());
		acquirerefundBean.setTradeType(2);
		acquirerefundCall.setData(false, acquirerefundBean);
		acquirerefundCall.callService();
		return acquirerefundBean;
	}
	/**
	 * 
	 * @param TradeNo
	 * @param refundAmt
	 * @return
	 * @throws Exception
	 */
	public static AcquireRefundBean AcquireRefund(String  TradeNo,
			String refundAmt) throws Exception {
		Logger.comment("申请部分退款");
		AcquireRefundBean acquirerefundBean = new AcquireRefundBean();
		AcquireRefundCall acquirerefundCall = new AcquireRefundCall();
		acquirerefundBean.setAppId("AutoTest");
		acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
		acquirerefundBean.setRefundAmt(refundAmt);
		acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
		acquirerefundBean.setTradeNo(TradeNo);
		acquirerefundBean.setBizNo(TestDataManager.getRandomUUID().toString());
		acquirerefundBean.setTradeType(2);
		acquirerefundCall.setData(false, acquirerefundBean);
		acquirerefundCall.callService();
		return acquirerefundBean;
	}
	/**
	 * 审核退款
	 * 
	 * @param aqb
	 * @throws Exception
	 */
	public static void approveRefund(AcquireOrderBean aqb) throws Exception {
		Logger.comment("审核退款");
		com.ymatou.paymentproxy.parameter.ApproveRefundBean approverefundBean = new com.ymatou.paymentproxy.parameter.ApproveRefundBean();
		com.ymatou.paymentproxy.service.ApproveRefundCall approverefundCall = new com.ymatou.paymentproxy.service.ApproveRefundCall();
		String pid = PayGateWayCallService.getPaymentId(aqb);
		approverefundBean.setApproveUser("AutoTest");
		List<String> PaymentIds = new ArrayList<String>();
		PaymentIds.add(pid);
		approverefundBean.setPaymentIds(PaymentIds);
		approverefundCall.setData(false, approverefundBean);
		approverefundCall.callService();
	}

	/**
	 * 审核退款
	 * 
	 * @param tradeNo
	 *            第三方支付生成的交易号
	 * @throws Exception
	 */
	public static void approveRefundByRefundIds(List<String> refundIdList)
			throws Exception {
		Logger.comment("审核退款");
		ApproveRefundBean approverefundBean = new ApproveRefundBean();
		ApproveRefundCall approverefundCall = new ApproveRefundCall();
		try {
			approverefundBean.setRefundIds(refundIdList);
			approverefundBean.setApproveUser("AutoTest");
			approverefundBean.setRefundIds(refundIdList);
			approverefundCall.setData(false, approverefundBean);
			approverefundCall.callService();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	/**
	 * 审核退款
	 * 
	 * @param tradeNo
	 *            第三方支付生成的交易号
	 * @throws Exception
	 */
	public static void approveRefundByTradeNo(String tradeNo) throws Exception {
		Logger.comment("审核退款");
		ApproveRefundBean approverefundBean = new ApproveRefundBean();
		ApproveRefundCall approverefundCall = new ApproveRefundCall();
		try {
			List<String> refundIdList = new ArrayList<String>();

			List<MRefund> refundRequestList = null;
			for (int i = 0; i < 6; i++) {

				refundRequestList = new PayGateWayWapper()
						.selectRefundRequestByTradeNo(tradeNo);

				if (!CollectionUtils.isEmpty(refundRequestList)) {
					break;
				}
				Thread.sleep(1000);
			}

			for (MRefund refundRequest : refundRequestList) {
				// 将所有该第三方支付交易下的退款，进行审核
				refundIdList.add(refundRequest.getRefundId().toString());
			}
			approverefundBean.setApproveUser("AutoTest");
			approverefundBean.setRefundIds(refundIdList);
			approverefundCall.setData(false, approverefundBean);
			approverefundCall.callService();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	/**
	 * java 审核退款
	 * 
	 * @param tradingid
	 * @param type
	 *            支付渠道
	 * @throws Exception
	 */

	public static void approveRefund(String tradingid) throws Exception {
		Logger.comment("审核退款");
		ApproveRefundCall approverefundCall = new ApproveRefundCall();
		com.ymatou.iapi.payment.parameter.ApproveRefundBean approverefundBean = new com.ymatou.iapi.payment.parameter.ApproveRefundBean();
		MRefund m = new PayGateWayWapper().selectRefundRequestByTradeNo(
				tradingid).get(0);
		String refundId = m.getRefundId().toString();
		approverefundBean.setApproveUser("AutoTest");
		List<String> refundIds = new ArrayList<String>();
		refundIds.add(refundId);
		approverefundBean.setRefundIds(refundIds);
		approverefundCall.setData(false, approverefundBean);
		approverefundCall.addDefHeader();
		String mockid = TestDataManager.getRandomUUID().toString();
		approverefundCall.addHeader("MockId", mockid);
		approverefundCall.addHeader("Mock", "1");
		approverefundCall.callService();
	}
	public static FastRefundBean fastRefund(AcquireOrderBean aqb) throws Exception {
		return fastRefund(aqb, null);
	}
	public static FastRefundBean fastRefund(AcquireOrderBean aqb,Map mock)
			throws Exception {
		Logger.comment("快速退款");
		FastRefundBean fastrefundBean = new FastRefundBean();
		FastRefundCall fastrefundCall = new FastRefundCall();
		String pid = PayGateWayCallService.getPaymentId(aqb);
		fastrefundBean.setAppId("AutoTest");
		// 这个是支付那里的订单号 目前随便填写
		List<String> OrderIdList = new ArrayList<String>();
		OrderIdList.add(TestDataManager.getRandomNum(9));
		fastrefundBean.setOrderIdList(OrderIdList);
		fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString()
				.replace("-", ""));
		fastrefundBean.setRefundNo(TestDataManager.getRandomUUID().toString()
				.replace("-", ""));
		fastrefundBean.setTradeType(1);
		fastrefundBean.setTradingId(aqb.getOrderId());
		fastrefundBean.setPaymentId(pid);
		fastrefundCall.setData(fastrefundBean);
		if(mock!=null) {
			addMock(fastrefundCall, mock);
		}
		fastrefundCall.callService();
		return fastrefundBean;
	}
	/**
	 * 初始化盛付通退款回调
	 * @param payment
	 * @param refundbn
	 * @param refundAmount
	 * @return
	 */
	public static SFTRefundNotifyBean initSFTRefundSend(MPayment payment,String refundbn,String refundAmount) {
		SFTRefundNotifyBean sftRefundNotifyBean = new SFTRefundNotifyBean();
		sftRefundNotifyBean.setVersion("V4.1.2.1.1");
		sftRefundNotifyBean.setCharset("UTF-8");
		sftRefundNotifyBean.setTraceNo(TestDataManager.getRandomUUID().toString());
		sftRefundNotifyBean.setOriginalOrderNo(payment.getPaymentId());
		sftRefundNotifyBean.setRefundAmount(refundAmount);
		sftRefundNotifyBean.setRefundOrderNo(refundbn);
		sftRefundNotifyBean.setRefundTransNo(TestDataManager.getRandomUUID().toString());
		sftRefundNotifyBean.setSenderId("SFT");
		sftRefundNotifyBean.setSendTime(YMTDateUtil.getBeforeOrNextDay(0, "yyyyMMddHHmmss"));
		sftRefundNotifyBean.setServiceCode("AUTOTEST");
		sftRefundNotifyBean.setStatus("01");
//		sftRefundNotifyBean.setSignMsg("");
		sftRefundNotifyBean.setSignType("MD5");
		sftRefundNotifyBean.setExt1("");
		sftRefundNotifyBean.setExt2("");
		sftRefundNotifyBean.setErrorCode("");
		sftRefundNotifyBean.setErrorMsg("");
		return sftRefundNotifyBean;
       
	}
	/**
	 * 初始化sft回调
	 * @param aqb
	 * @return
	 * @throws Exception
	 */
	public static SFTNotifyBean initSFTNotifyBean(AcquireOrderBean aqb) throws Exception {
		SFTNotifyBean SFTNotifyBean=new SFTNotifyBean();
//		Name=REP_B2CPAYMENT&
		SFTNotifyBean.setName("REP_B2CPAYMENT");
//				Version=V4.1.2.1.1&
		SFTNotifyBean.setVersion("V4.1.2.1.1");
//				Charset=UTF-8&
		SFTNotifyBean.setCharset("UTF-8");
//				TraceNo=c3a49341-b772-4024-ab9c-0848ee8ea064&
		SFTNotifyBean.setTraceNo(TestDataManager.getRandomUUID().toString());
//				MsgSender=SFT&
		SFTNotifyBean.setMsgSender("SFT");
//				SendTime=20171222111220&
		SFTNotifyBean.setSendTime(YMTDateUtil.getBeforeOrNextDay(0, "yyyyMMddHHmmss"));
//				InstCode=SFT&
		SFTNotifyBean.setInstCode("SFT");
//				OrderNo=f2e03275ee25488f99e58630dfb02552&
		String orderNo = getPaymentId(aqb);
		SFTNotifyBean.setOrderNo(orderNo);
//				OrderAmount=3.00&
		SFTNotifyBean.setOrderAmount(aqb.getPayPrice());
//				TransNo=C20171222111120651783&
		SFTNotifyBean.setTransNo(TestDataManager.getRandomUUID().toString());
//				TransAmount=3.00&
		SFTNotifyBean.setTransAmount(aqb.getPayPrice());
//				TransStatus=01&
		SFTNotifyBean.setTransStatus("01");
//				TransType=PT314&
		SFTNotifyBean.setTransType("PT314");
//				TransTime=20171222111214&
		SFTNotifyBean.setTransTime(YMTDateUtil.getBeforeOrNextDay(0, "yyyyMMddHHmmss"));
//				MerchantNo=540511&
		SFTNotifyBean.setMerchantNo(SFTMerchantNo);
//				PaymentNo=CP20171222111120380064&
		SFTNotifyBean.setPaymentNo(TestDataManager.getRandomUUID().toString());
//				ErrorCode=&
		SFTNotifyBean.setErrorCode("");
//				ErrorMsg=&
		SFTNotifyBean.setErrorMsg("");
//				PayableFee=0.00&
		SFTNotifyBean.setPayableFee("0.00");
//				ReceivableFee=0.15&
		SFTNotifyBean.setReceivableFee("0.00");
//				PayChannel=wp&
		SFTNotifyBean.setPayChannel("wl");
//				paymentDetail=&
		SFTNotifyBean.setPaymentDetail("");
//				SignType=NONEED&
		SFTNotifyBean.setSignType("NONEED");
//				SignMsg=3EBB7EF173E09D2A2168572AEF867B27&
//				Ext1=&
		String ext="{\"appid\":\"wxe05a3aa89d0a89be\"}";
		SFTNotifyBean.setExt1(ext);
//				Ext2=
		SFTNotifyBean.setExt2(ext);
		SFTNotifyBean.setErrorCode("");
		SFTNotifyBean.setErrorMsg("");
		return SFTNotifyBean;
		
	}
	/**
	 * 转换盛付通bean
	 * @param SFTNotifyBean
	 * @return
	 */
	public static String SFTPayNotifyBeanToSend(SFTNotifyBean SFTNotifyBean) {
		//Name+Version+Charset+TraceNo+MsgSender+SendTime+InstCode+OrderNo+OrderAmount+ TransNo+TransAmount+TransStatus+TransType+TransTime+MerchantNo+
		//ErrorCode+ErrorMsg	+Ext1+Ext2+SignType+merchantKey
		StringBuffer tosign=new StringBuffer();
		tosign.append(SFTNotifyBean.getName()!=null?SFTNotifyBean.getName():"");
		tosign.append(SFTNotifyBean.getVersion()!=null?SFTNotifyBean.getVersion():"");
		tosign.append(SFTNotifyBean.getCharset()!=null?SFTNotifyBean.getCharset():"");
		tosign.append(SFTNotifyBean.getTraceNo()!=null?SFTNotifyBean.getTraceNo():"");
		tosign.append(SFTNotifyBean.getMsgSender()!=null?SFTNotifyBean.getMsgSender():"");
		tosign.append(SFTNotifyBean.getSendTime()!=null?SFTNotifyBean.getSendTime():"");
		tosign.append(SFTNotifyBean.getInstCode()!=null?SFTNotifyBean.getInstCode():"");
		tosign.append(SFTNotifyBean.getOrderNo()!=null?SFTNotifyBean.getOrderNo():"");
		tosign.append(SFTNotifyBean.getOrderAmount()!=null?SFTNotifyBean.getOrderAmount():"");
		tosign.append(SFTNotifyBean.getTransNo()!=null?SFTNotifyBean.getTransNo():"");
		tosign.append(SFTNotifyBean.getTransAmount()!=null?SFTNotifyBean.getTransAmount():"");
		tosign.append(SFTNotifyBean.getTransStatus()!=null?SFTNotifyBean.getTransStatus():"");
		tosign.append(SFTNotifyBean.getTransType()!=null?SFTNotifyBean.getTransType():"");
		tosign.append(SFTNotifyBean.getTransTime()!=null?SFTNotifyBean.getTransTime():"");
		tosign.append(SFTNotifyBean.getMerchantNo()!=null?SFTNotifyBean.getMerchantNo():"");
		tosign.append(SFTNotifyBean.getErrorCode()!=null?SFTNotifyBean.getErrorCode():"");
		tosign.append(SFTNotifyBean.getErrorMsg()!=null?SFTNotifyBean.getErrorMsg():"");
		tosign.append(SFTNotifyBean.getExt1()!=null?SFTNotifyBean.getExt1():"");
		tosign.append(SFTNotifyBean.getExt2()!=null?SFTNotifyBean.getExt2():"");
		tosign.append(SFTNotifyBean.getSignType()!=null?SFTNotifyBean.getSignType():"");
		tosign.append(SFTMerchantKey);
		Logger.debug("SFT tosign:"+tosign);
		String sign=TestDataManager.getMD5(tosign.toString().getBytes()).toUpperCase();
		
		SFTNotifyBean.setSignMsg(sign);
//		SFTNotifyBean.setSignType("NONEED");
		SFTNotifyBean.setExt1(FormatUtil.urlEncode(SFTNotifyBean.getExt1()));
		SFTNotifyBean.setExt2(FormatUtil.urlEncode(SFTNotifyBean.getExt2()));
		return FormatUtil.beanToHttpString(SFTNotifyBean,false,false);
	}
	/**
	 * 转换盛付通退款bean
	 * @param SFTNotifyBean
	 * @return
	 */
	public static String SFTRefundPayNotifyBeanToSend(SFTRefundNotifyBean SFTRefundNotifyBean) { //ServiceCode+Version+Charset+TraceNo+SenderId+SendTime+RefundOrderNo+OriginalOrderNo+Status+RefundAmount+RefundTransNo+SignType
		StringBuffer tosign=new StringBuffer();
		tosign.append(SFTRefundNotifyBean.getServiceCode()!=null?SFTRefundNotifyBean.getServiceCode():"");
		tosign.append(SFTRefundNotifyBean.getVersion()!=null?SFTRefundNotifyBean.getVersion():"");
		tosign.append(SFTRefundNotifyBean.getCharset()!=null?SFTRefundNotifyBean.getCharset():"");
		tosign.append(SFTRefundNotifyBean.getTraceNo()!=null?SFTRefundNotifyBean.getTraceNo():"");
		tosign.append(SFTRefundNotifyBean.getSenderId()!=null?SFTRefundNotifyBean.getSenderId():"");
		tosign.append(SFTRefundNotifyBean.getSendTime()!=null?SFTRefundNotifyBean.getSendTime():"");
		tosign.append(SFTRefundNotifyBean.getRefundOrderNo()!=null?SFTRefundNotifyBean.getRefundOrderNo():"");
		tosign.append(SFTRefundNotifyBean.getOriginalOrderNo()!=null?SFTRefundNotifyBean.getOriginalOrderNo():"");
		tosign.append(SFTRefundNotifyBean.getStatus()!=null?SFTRefundNotifyBean.getStatus():"");
		tosign.append(SFTRefundNotifyBean.getRefundAmount()!=null?SFTRefundNotifyBean.getRefundAmount():"");
		tosign.append(SFTRefundNotifyBean.getRefundTransNo()!=null?SFTRefundNotifyBean.getRefundTransNo():"");
		tosign.append(SFTRefundNotifyBean.getSignType()!=null?SFTRefundNotifyBean.getSignType():"");
		tosign.append(SFTMerchantKey);
		Logger.debug("SFT tosign:"+tosign);
		String sign=TestDataManager.getMD5(tosign.toString().getBytes()).toUpperCase();
		
		SFTRefundNotifyBean.setSignMsg(sign);
//		SFTRefundNotifyBean.setSignType("MD5");
		return FormatUtil.beanToHttpString(SFTRefundNotifyBean,false,false);
	}
	/**
	 * AliPayNotifyBean加签并转换为SendString
	 * 
	 * @param alipaybean
	 * @return
	 * @throws Exception
	 */
	public static String aliPayNotifyBeanToSend(AliPayNotifyBean alipaybean,
			String type) throws Exception {
		Logger.comment("AliPayNotifyBean加签并转换为SendString");
		String send = null;
		if (type.equals("13")|| type.equals("3013")|| type.equals("3113")|| type.equals("3213")|| type.equals("9")||type.equals("1013") || type.equals("1009")|| type.equals("8")|| type.equals("2013") || type.equals("4013")) {
			// 排序加签名
			String src = FormatUtil.beanToHttpString(alipaybean, false);
			String sign = Sign.SignSHA1WithRSA(src);
			alipaybean.setSign(sign);
			alipaybean.setSign_type("RSA");
			// 转换成最终发出的数据
			send = FormatUtil.beanToHttpString(alipaybean, true);
		} else {
			String src = FormatUtil.beanToHttpString(alipaybean, false);
			String sign = new Sign().signMd5(alipaybean, Sign.autoTestKey);
			alipaybean.setSign(sign);
			alipaybean.setSign_type("MD5");
			send = FormatUtil.beanToHttpString(alipaybean, true);
		}
		return send;
	}

	/**
	 * WeiXinNotifyBean加签并转换为SendString
	 * 
	 * @param weixinbean
	 * @return
	 * @throws Exception
	 */
	public static String weiXinNotifyBeanToSend(WeiXinNotifyBean weixinbean)
			throws Exception {
		Logger.comment("WeiXinNotifyBean加签并转换为SendString");
		// 排序加签名
		// String src = FormatUtil.beanToHttpString(weixinbean, false);
		// String sign = SignSHA1WithRSA(src);

		String sign = new Sign()
				.signMd5(weixinbean, "&key=" + Sign.autoTestKey);
		weixinbean.setSign(sign);

		// 转换成最终发出的数据
		String send = FormatUtil.beanToXmlString(weixinbean);
		return send;
	}
	/**
	 * 根据type获取merchantId
	 * @param type
	 * @return
	 */
	public static String getMerchantId(String type){
		String mid=new String("");
		if(type.length()==4&&type.startsWith("10")){
			type=type.substring(2);
		}
		if (type.equals("14")) {
			mid=PayGateWayCallService.WX_Wap_merchantId;
		} else if (type.equals("16")||type.equals("4016")) {
			mid=PayGateWayCallService.WX_Wap_merchantId;
		} else if (type.equals("17")) {
			mid=PayGateWayCallService.WX_Wap_merchantId;
		}  else if (type.equals("3017")) {
			mid=PayGateWayCallService.WX_QQG_merchantId;
		} else if (type.equals("3015")) {
			mid=PayGateWayCallService.WX_QQG_merchantId2;
		}
		else if (type.equals("3117")) {
			mid=PayGateWayCallService.WX_QQG_merchantId_Could;
		} else if (type.equals("3115")) {
			mid=PayGateWayCallService.WX_QQG_merchantId_Could;
		}else if (type.equals("3215")) {
			mid=PayGateWayCallService.WX_QQG_merchantId_Could;
		}
		else if (type.equals("18")) {
			mid=PayGateWayCallService.LiveShop_merchantId;
		}else if (type.equals("19")) {
			mid=PayGateWayCallService.WX_HS_merchantId;
		}
		if(type.equals("10")){
			mid=PayGateWayCallService.Alipay_MERID;
		}else if(type.equals("9")){
			mid=PayGateWayCallService.Alipay_MERID;
		}else if(type.equals("8")){
			mid=PayGateWayCallService.Alipay_MERID;
		}else if(type.equals("11")){
			mid=PayGateWayCallService.Alipay_MERID;
		}
		else if(type.equals("13")||type.equals("3013")|| type.equals("4013")){
			mid=PayGateWayCallService.Alipay_MERID;
		}
		else if(type.equals("13")||type.equals("3113")||type.equals("3213")){
			mid=PayGateWayCallService.Alipay_MERID_Could;
		}
		
		if(type.equals("50")){
			mid=PayGateWayCallService.CMB_SITMERID;
		}
		if(type.equals("60")||type.equals("61")){
			mid=PayGateWayCallService.APPLEPAY_MERID;
		}
		if(type.equals("70")){
			mid=PayGateWayCallService.BaoFu_MERID;
		}
		if(type.equals("80")){
			mid=PayGateWayCallService.BESTPAY_MERID;
		}
		if(type.equals("6010")||type.equals("6011")){
			mid=PayGateWayCallService.SFTMerchantNo;
		}
		if(type.equals("6000")||type.equals("6001")||type.equals("6002")||type.equals("6003")||type.equals("6006")|type.equals("6103")|type.equals("6107")){
			mid=PayGateWayCallService.GdDefMerchantNo;
		}
		if(type.equals("6100")){
			mid=PayGateWayCallService.GODAliPay_MERID;
		}
		//头条抖音返回支付宝商户号
		if(type.equals("2013")){
			mid=PayGateWayCallService.Alipay_LOGIN_MERID;
		}
		return mid;
	}
	/**
	 * 初始化 WeiXinNotifyBean
	 * 
	 * @param aqb
	 * @return
	 * @throws InterruptedException
	 */
	public static WeiXinNotifyBean initWeixinBean(AcquireOrderBean aqb)
			throws InterruptedException {
		Logger.comment("初始化默认WeiXinNotifyBean,微信回调xml");
		// <xml><appid><![CDATA[wxf51a439c0416f182]]></appid>
		// <bank_type><![CDATA[CMB_DEBIT]]></bank_type>
		// <cash_fee><![CDATA[8200]]></cash_fee>
		// <fee_type><![CDATA[CNY]]></fee_type>
		// <is_subscribe><![CDATA[N]]></is_subscribe>
		// <mch_id><![CDATA[1234079001]]></mch_id>
		// <nonce_str><![CDATA[b82bbe0b28954973ad2a9c98618af516]]></nonce_str>
		// <openid><![CDATA[oASzYjrBI-LG8JMNSIC3c5VSynGU]]></openid>
		// <out_trade_no><![CDATA[20160412172258588000000000023844]]></out_trade_no>
		// <result_code><![CDATA[SUCCESS]]></result_code>
		// <return_code><![CDATA[SUCCESS]]></return_code>
		// <sign><![CDATA[E39042D497F3952F55F17D310B58EC36]]></sign>
		// <time_end><![CDATA[20160412172307]]></time_end>
		// <total_fee>8200</total_fee>
		// <trade_type><![CDATA[APP]]></trade_type>
		// <transaction_id><![CDATA[4009562001201604124771601467]]></transaction_id>
		// </xml>
		WeiXinNotifyBean wxnotifyBean = new WeiXinNotifyBean();
		wxnotifyBean.setAppid(WX_DefAppID);
		if (aqb.getPayType().equals("17")) {
			wxnotifyBean.setAppid(PayGateWayCallService.WX_AppID);
		}
		else if (aqb.getPayType().equals("18")) {
			wxnotifyBean.setAppid(PayGateWayCallService.LiveShop_AppId);
		}
		else if (aqb.getPayType().equals("19")) {
			wxnotifyBean.setAppid(PayGateWayCallService.WX_HS_AppID);
		}
		else if (aqb.getPayType().equals("3017")) {
			wxnotifyBean.setAppid(PayGateWayCallService.WX_QQG_AppID);
		}
		else if (aqb.getPayType().equals("3015")) {
			wxnotifyBean.setAppid(PayGateWayCallService.WX_QQG_AppID2);
		}else if (aqb.getPayType().equals("3117")) {
			wxnotifyBean.setAppid(PayGateWayCallService.WX_QQG_AppID_Could_17);
		}
		else if (aqb.getPayType().equals("3115")) {
			wxnotifyBean.setAppid(PayGateWayCallService.WX_QQG_AppID_Could_15);
		}
		else if (aqb.getPayType().equals("3215")) {
			wxnotifyBean.setAppid(PayGateWayCallService.WX_QQG_AppID_Could_15_YDD);
		}
		wxnotifyBean.setAttach(TestDataManager.getRandomUUID().toString());
		wxnotifyBean.setBank_type(BankIdEnum.CMB.name());
		Double payprice = Double.valueOf(aqb.getPayPrice());
		int iprice = (int) (payprice * 100);
		Logger.debug("iprice:" + iprice);
		wxnotifyBean.setCash_fee(String.valueOf(iprice));
		wxnotifyBean.setCash_fee_type(null);
		wxnotifyBean.setCoupon_count("0");
		wxnotifyBean.setCoupon_fee("0");
		wxnotifyBean.setDevice_info(TestDataManager.getRandomUUID().toString());
		wxnotifyBean.setErr_code(null);
		wxnotifyBean.setErr_code_des(null);
		wxnotifyBean.setFee_type("CNY");
		wxnotifyBean.setIs_subscribe("N");
		if (aqb.getPayType().equals("14")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_Wap_merchantId);
		} else if (aqb.getPayType().equals("16")||aqb.getPayType().equals("4016")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_Wap_merchantId);
		} else if (aqb.getPayType().equals("17")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_Wap_merchantId);
		} else if (aqb.getPayType().equals("18")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.LiveShop_merchantId);
		}else if (aqb.getPayType().equals("19")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_HS_merchantId);
		}else if (aqb.getPayType().equals("3017")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_QQG_merchantId);
		} else if (aqb.getPayType().equals("3015")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_QQG_merchantId2);
		} else if (aqb.getPayType().equals("3117")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_QQG_merchantId_Could);
		} else if (aqb.getPayType().equals("3115")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_QQG_merchantId_Could);
		} else if (aqb.getPayType().equals("3215")) {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_QQG_merchantId_Could);
		}else {
			wxnotifyBean.setMch_id(PayGateWayCallService.WX_App_merchantId);
		}
		wxnotifyBean.setNonce_str(TestDataManager.getRandomUUID().toString()
				.replace("-", "").substring(0, 31));
		// Map m = new DefaultWapper().selectLastWeixinUser();
		String uid = new JUserWapper().selectWXUser().getUserId().toString();
		String opid = new JUserWapper().selectWXUser().getOpenId();
		wxnotifyBean.setOpenid(opid);
		// wxnotifyBean.setOpenid("1234567");
		// trandno 是PaymentId
		// PPBussinessOrder ppb = new
		// PayGateWayWapper().selectPPBussinessorderByTraceId(aqb.getTraceId()).get(0);
		// 根据支付的第三方交易号，及表中的orderid 查询ppb
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		wxnotifyBean.setOut_trade_no(trandno);
		wxnotifyBean.setResult_code("SUCCESS");
		wxnotifyBean.setTime_end(YMTDateUtil.getSysTime("yyyyMMddHHmmss"));
		wxnotifyBean.setTotal_fee(String.valueOf(iprice));
		if (aqb.getPayType().equals("14")) {
			wxnotifyBean.setTrade_type("JSAPI");
		} else if (aqb.getPayType().equals("15")) {
			wxnotifyBean.setTrade_type("APP");
		} else {
			wxnotifyBean.setTrade_type("NATIVE");
		}
		wxnotifyBean.setTransaction_id(TestDataManager.getRandomUUID()
				.toString().replace("-", "").substring(0, 31));
		wxnotifyBean.setReturn_code("SUCCESS");
		wxnotifyBean.setReturn_msg("成功");
		return wxnotifyBean;
	}

	/**
	 * 获取PaymentId
	 * 
	 * @param aqb
	 *            收单bean
	 * @return 对应的PaymentId
	 * @throws Exception
	 */
	public static String getPaymentId(AcquireOrderBean aqb) throws Exception {
		Logger.comment("通过AcquireOrderBean获取PaymentId");
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		return trandno;
	}

	/**
	 * 获取PPayment
	 * 
	 * @param aqb
	 *            收单bean
	 * @return 对应的PPayment
	 * @throws Exception
	 */
	public static MPayment getPPayment(AcquireOrderBean aqb) throws Exception {
		Logger.comment("通过AcquireOrderBean获取PPayment");
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		return ppm;
	}

	/**
	 * aliwap Notify加签
	 * 
	 * @param src
	 *            xml报文
	 * @return 全报文
	 */
	public static String signAliWapNotify(String src) {
		String tempsrc = "service=alipay.wap.trade.create.direct&v=1.0&sec_id=MD5&notify_data="
				+ src + Sign.autoTestKey;
		String md5 = TestDataManager.getMD5(tempsrc.getBytes());
		src = "service=alipay.wap.trade.create.direct&sign=" + md5
				+ "&v=1.0&sec_id=MD5&notify_data=" + FormatUtil.urlEncode(src);
		return src;
	}

	/**
	 * aliwap Notify加签
	 * 
	 * @param src
	 *            xml报文
	 * @return 全报文
	 */
	// TODO 需要改造 wap 走rsa校验
	public static String signAliWapNotify(AliPayWapNotifyBean aliwap) {
		String src = "<notify>" + FormatUtil.beanToNoRootXmlString(aliwap)
				+ "</notify>";
		String tempsrc = "service=alipay.wap.trade.create.direct&v=1.0&sec_id=MD5&notify_data="
				+ src + Sign.autoTestKey;
		String md5 = TestDataManager.getMD5(tempsrc.getBytes());
		src = "service=alipay.wap.trade.create.direct&sign=" + md5
				+ "&v=1.0&sec_id=MD5&notify_data=" + FormatUtil.urlEncode(src);
		return src;
	}

	/**
	 * RSA
	 * 
	 * @param aliwap
	 * @return
	 * @throws Exception
	 */
	public static String signRSAAliWapNotify(AliPayWapNotifyBean aliwap)
			throws Exception {
		String src = "<notify>" + FormatUtil.beanToNoRootXmlString(aliwap)
				+ "</notify>";
		String tempsrc = "service=alipay.wap.trade.create.direct&v=1.0&sec_id=0001&notify_data="
				+ src;
		Logger.debug("tempsrc:"+tempsrc);
		String rsasign = FormatUtil.urlEncode(new Sign().SignSHA1WithRSA(
				tempsrc, false));
		byte[] rsabytes = RSAUtils.encryptByPublicKey(src.getBytes(),
				(RSAPublicKey) RSAUtils.loadPublicKey(EnvSetup
						.getData("publicK")));
		String base64src = Base64.getEncoder().encodeToString(rsabytes);
		//		Logger.debug(RSAUtils.decryptByPrivateKey(base64src, (RSAPrivateKey) RSAUtils.loadPrivateKey(EnvSetup.getData("privateK"))));
		src = "service=alipay.wap.trade.create.direct&v=1.0&sec_id=0001&notify_data="
				+ FormatUtil.urlEncode(base64src) + "&sign=" + rsasign;
		return src;
	}

	/**
	 *  applepay Notify加签
	 * 
	 * @param 初始化过的ApplePayNotifyBean
	 * @return 全报文
	 */
	public static String signApplePayNotify(ApplePayNotifyBean applepay)
			throws Exception {
		// 转换成表单格式 不转码
		String plaintext = FormatUtil.beanToHttpString(applepay, false);
		// sha1加签
		byte[] signDigest = SecurityUtil.sha1(plaintext,
				ApplePayConstants.encoding);
		// 转换16进制
		signDigest = Hex.toHexBytes(signDigest, ApplePayConstants.encoding);
		PrivateKey privateKey = RSAUtils.loadPrivateKey(EnvSetup
				.getData("privateK"));
		// rsa加密
		byte[] signData = SecurityUtil.signWithSha1Rsa(privateKey, signDigest);
		// base64转码
		signData = Base64.getEncoder().encode(signData);
		applepay.setSignature(new String(signData));
		// 转换成表单格式 转码
		String send = FormatUtil.beanToHttpString(applepay, true);
		return send;
	}

	/**
	 * 初始化 AliPayWapNotifBean
	 * 
	 * @param aqb
	 * @return
	 * @throws InterruptedException
	 */
	public static AliPayWapNotifyBean initAliPayWapNotify(AcquireOrderBean aqb)
			throws InterruptedException {
		AliPayWapNotifyBean aliwap = new AliPayWapNotifyBean();
		aliwap.setBuyer_email(TestDataManager.getEmail());
		aliwap.setBuyer_id("2088" + TestDataManager.getRandomNum(10));
		aliwap.setGmt_create(YMTDateUtil.getBeforeOrNextSecond(1));
		aliwap.setGmt_payment(YMTDateUtil.getBeforeOrNextSecond(2));
		aliwap.setIs_total_fee_adjust("N");
		aliwap.setNotify_id(TestDataManager.getClientpaymentId());
		aliwap.setNotify_time(YMTDateUtil.getBeforeOrNextSecond(3));
		aliwap.setNotify_type("trade_status_sync");
		// trandno 是PaymentId
		// PPBussinessorder ppb = new
		// PayGateWayWapper().selectPPBussinessorderByTraceId(aqb.getTraceId()).get(0);
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		aliwap.setOut_trade_no(trandno);
		aliwap.setPayment_type("1");
		aliwap.setPrice(aqb.getPayPrice());
		aliwap.setQuantity("1");
		aliwap.setSeller_email(PayGateWayCallService.Alipay_EMAIL);
		aliwap.setSeller_id(PayGateWayCallService.Alipay_MERID);
		aliwap.setSubject(aqb.getProductName());
		aliwap.setTotal_fee(aqb.getPayPrice());
		aliwap.setTrade_no(TestDataManager.getRandomUUID().toString());
		aliwap.setTrade_status("TRADE_SUCCESS");
		aliwap.setUse_coupon("N");
		return aliwap;
	}

	public static BaoFuRefundNotifyBean initBaoFuRefundNotifyBean(
			AcquireOrderBean aqb) throws InterruptedException {
		BaoFuRefundNotifyBean aprf = new BaoFuRefundNotifyBean();
		Integer price = new BigDecimal(aqb.getPayPrice()).multiply(
				new BigDecimal(100)).intValue();
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		MRefund RefundRequest = new PayGateWayWapper()
				.selectRefundRequestByPaymentid(ppm.getPaymentId()).get(0);
		aprf.setMember_id(BaoFu_MERID);
		aprf.setRefund_amt(price.toString());
		aprf.setRefund_order_no(RefundRequest.getRefundBatchNo());
		aprf.setRefund_business_no(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
		aprf.setResp_code("0000");
		aprf.setResp_msg("成功");
		return aprf;
	}

	/**
	 * 初始化退款回调
	 * 
	 * @param aqb
	 * @return
	 * @throws Exception
	 */
	private static RefundNotifyBean initRefundNotifyBean(AcquireOrderBean aqb)
			throws Exception {
		RefundNotifyBean refundnotifyBean = new RefundNotifyBean();
		RefundNotifyCall refundnotifyCall = new RefundNotifyCall();
		refundnotifyBean.setNotify_time(DataManager.getSysTime());
		refundnotifyBean.setNotify_type("batch_refund_notify");
		refundnotifyBean.setNotify_id(TestDataManager.getClientpaymentId());
		try {
			// 根据第三方支付返回的交易号查询第三方支付单号
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
					aqb.getOrderId()).get(0);

			MRefund RefundRequest = new PayGateWayWapper()
					.selectRefundRequestByPaymentid(ppm.getPaymentId()).get(0);
			String result_details = ppm.getInstitutionPaymentId() + "^"
					+ aqb.getPayPrice() + "^SUCCESS"
					+ "$"+PayGateWayCallService.Alipay_EMAIL+"^"+PayGateWayCallService.Alipay_MERID+"^0.01^SUCCESS";
			refundnotifyBean.setResult_details(result_details);
			refundnotifyBean.setBatch_no(RefundRequest.getRefundBatchNo());
			refundnotifyBean.setSuccess_num("1");
		} catch (Exception e) {
			Logger.debug("" + e.getMessage());
		}
		return refundnotifyBean;
	}

	/**
	 * 初始化退款回调
	 * 
	 * @param RefundRequest
	 *            refundRequest 退款申请单
	 * @return
	 * @throws Exception
	 */
	private static RefundNotifyBean initRefundNotifyBean(MRefund refundRequest)
			throws Exception {
		RefundNotifyBean refundnotifyBean = new RefundNotifyBean();
		RefundNotifyCall refundnotifyCall = new RefundNotifyCall();
		refundnotifyBean.setNotify_time(DataManager.getSysTime());
		refundnotifyBean.setNotify_type("batch_refund_notify");
		refundnotifyBean.setNotify_id(TestDataManager.getClientpaymentId());
		String InstPaymentId = new PayGateWayWapper()
				.selectPPPaymentByPaymentId(refundRequest.getPaymentId())
				.get(0).getInstitutionPaymentId();
		try {
			String result_details = InstPaymentId + "^"
					+ refundRequest.getRefundAmt().setScale(2).toString()
					+ "^SUCCESS"
					+ "$"+PayGateWayCallService.Alipay_EMAIL+"^"+PayGateWayCallService.Alipay_MERID+"^0.01^SUCCESS";
			refundnotifyBean.setResult_details(result_details);
			refundnotifyBean.setBatch_no(refundRequest.getRefundBatchNo());
			refundnotifyBean.setSuccess_num("1");
		} catch (Exception e) {
			Logger.debug("" + e.getMessage());
		}
		return refundnotifyBean;
	}

	/**
	 * 获取ali退款回调sendstring
	 * 
	 * @param refundNotifyBean
	 * @param aqb
	 * @return
	 * @throws Exception
	 */
	private static String aliPayRefundNotifyToSend(
			RefundNotifyBean refundNotifyBean, AcquireOrderBean aqb)
			throws Exception {
		Logger.comment("aliPayRefundNotify加签并转换为SendString");
		String send = null;
		if (aqb.getPayType().equals("13") || aqb.getPayType().equals("9") || aqb.getPayType().equals("3013") || aqb.getPayType().equals("3113")|| aqb.getPayType().equals("8") || aqb.getPayType().equals("2013") || aqb.getPayType().equals("4013")) {
			// 排序加签名
			String src = FormatUtil.beanToHttpString(refundNotifyBean, false);
			String sign = new Sign().SignSHA1WithRSA(src);
			refundNotifyBean.setSign(sign);
			refundNotifyBean.setSign_type("RSA");
			// 转换成最终发出的数据
			send = FormatUtil.beanToHttpString(refundNotifyBean, true);
		} else {
			String src = FormatUtil.beanToHttpString(refundNotifyBean, false);
			String sign = new Sign()
					.signMd5(refundNotifyBean, Sign.autoTestKey);
			refundNotifyBean.setSign(sign);
			refundNotifyBean.setSign_type("MD5");
			send = FormatUtil.beanToHttpString(refundNotifyBean, true);
		}
		return send;
	}

	public static ApplePayNotifyBean initApplePayNotifyBean(AcquireOrderBean aqb)
			throws InterruptedException {
		ApplePayNotifyBean applyPayNotifyBean = new ApplePayNotifyBean();
		// trandno 是PaymentId
		// PPBussinessorder ppb = new
		// PayGateWayWapper().selectPPBussinessorderByTraceId(aqb.getTraceId()).get(0);
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();

		Integer price = Integer
				.valueOf((int) (Double.valueOf(aqb.getPayPrice()) * 100));

		applyPayNotifyBean.setBizType("000201");// 000201
		applyPayNotifyBean.setOrderId(trandno);// 17050410190438490

		applyPayNotifyBean.setTraceNo(TestDataManager.getRandomUUID()
				.toString().replaceAll("-", ""));// 78591936

		applyPayNotifyBean.setSettleAmt(price);// 101

		applyPayNotifyBean.setSettleCurrencyCode("156");// 156
		applyPayNotifyBean.setTxnType("01");// 01+

		applyPayNotifyBean.setQueryId(TestDataManager.getRandomUUID()
				.toString().replaceAll("-", ""));// 78591936

		applyPayNotifyBean.setAccessType("0");// 0
		applyPayNotifyBean.setTxnTime(YMTDateUtil.getSysTime("yyyyMMddHHmmss"));// 20170504101911
		applyPayNotifyBean.setPayCardType("01");// 01
		applyPayNotifyBean.setTxnSubType("01");// 01
		applyPayNotifyBean.setEncoding("UTF-8");// UTF-8
		applyPayNotifyBean.setVersion("5.0.0");// 5.0.0
		applyPayNotifyBean.setRespMsg("paysuccess");// paysuccess
		applyPayNotifyBean.setMerId(APPLEPAY_MERID);// 308310053994237
		applyPayNotifyBean.setCurrencyCode("156");// 156
		applyPayNotifyBean.setRespCode("00");// 00
		applyPayNotifyBean.setSignMethod("01");// 01

		applyPayNotifyBean.setTxnAmt(price);// 101
		return applyPayNotifyBean;
	}

	public static ApplePayRefundNotifyBean initApplePayRefundNotifyBean(
			AcquireOrderBean aqb) throws InterruptedException {
		ApplePayRefundNotifyBean aprf = new ApplePayRefundNotifyBean();
		Integer price = new BigDecimal(aqb.getPayPrice()).multiply(
				new BigDecimal(100)).intValue();
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		MRefund RefundRequest = new PayGateWayWapper()
				.selectRefundRequestByPaymentid(ppm.getPaymentId()).get(0);
		aprf.setCurrencyCode("156");
		aprf.setMerId(PayGateWayCallService.APPLEPAY_MERID);
		aprf.setOrderId(RefundRequest.getRefundBatchNo());
		aprf.setRespCode("00");
		aprf.setTxnAmt(price.toString());
		return aprf;
	}

	public static String ApplePayRefundNotifyToSend(
			ApplePayRefundNotifyBean applerfb, AcquireOrderBean aqb)
			throws Exception {
		String plaintext = FormatUtil.beanToHttpString(applerfb, false);
		byte[] signDigest = SecurityUtil.sha1(plaintext,
				ApplePayConstants.encoding);
		signDigest = Hex.toHexBytes(signDigest, ApplePayConstants.encoding);
		PrivateKey privateKey = RSAUtils.loadPrivateKey(EnvSetup
				.getData("privateK"));
		byte[] signData = SecurityUtil.signWithSha1Rsa(privateKey, signDigest);
		signData = Base64.getEncoder().encode(signData);
		applerfb.setSignature(new String(signData));
		String send = FormatUtil.beanToHttpString(applerfb, true);
		return send;
	}
	/**
	 * 翼支付
	 * @param aqb
	 * @return
	 * @throws InterruptedException
	 */
	public static BestPayNotifyBean initBestPayNotifyBean(AcquireOrderBean aqb) throws InterruptedException {
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		BestPayNotifyBean bestbay=new BestPayNotifyBean();
		bestbay.setATTACH(null);
		bestbay.setATTACHAMOUNT("0");
		//默认翼支付卡
		bestbay.setBANKID("BESTCARD");
		bestbay.setENCODETYPE("1");
		bestbay.setMERCHANTID(PayGateWayCallService.BESTPAY_MERID);
		bestbay.setORDERAMOUNT(aqb.getPayPrice());
		//TODO 格式 yyyyMMDDhhmmss+（不小于 4	位）流水号。与订单号填一致??目前传订单号
		bestbay.setORDERREQTRANSEQ(trandno);
		bestbay.setORDERSEQ(trandno);
		bestbay.setPRODUCTAMOUNT(aqb.getPayPrice());
		bestbay.setPRODUCTNO(null);
		bestbay.setRETNCODE("0000");
		bestbay.setRETNINFO("0000");
		//签名需要加密 后续运算
		bestbay.setSIGN(null);
		bestbay.setTRANDATE(YMTDateUtil.getBeforeOrNextDay(0, "yyyyMMdd"));
		bestbay.setUPBANKTRANSEQ(null);
		bestbay.setUPREQTRANSEQ(trandno);
		bestbay.setUPTRANSEQ(TestDataManager.getClientpaymentId());
		bestbay.setURTYPE("RMB");
		return bestbay;
	}
	/**
	 * 翼支付回调报文
	 * @param bestPayNotifyBean
	 * @return
	 */
	public static String bestNotifyBeanToSend(BestPayNotifyBean bestPayNotifyBean) {
		StringBuffer soucreString=new StringBuffer();
//		UPTRANSEQ=20080101000001&MERCHANTID=0250000001&ORDERSEQ=2006050112564931556&
//		ORDERAMOUNT=10000&RETNCODE=0000&RETNINFO=0000&TRANDATE=20060101&KEY=3
//				44C4FB521F5A52EA28FB7FC79AEA889478D4343E4548C02

		soucreString.append("UPTRANSEQ=");
		soucreString.append(bestPayNotifyBean.getUPTRANSEQ());
		soucreString.append("&MERCHANTID=");
		soucreString.append(bestPayNotifyBean.getMERCHANTID());
		soucreString.append("&ORDERSEQ=");
		soucreString.append(bestPayNotifyBean.getORDERSEQ());
		soucreString.append("&ORDERAMOUNT=");
		soucreString.append(bestPayNotifyBean.getORDERAMOUNT());
		soucreString.append("&RETNCODE=");
		soucreString.append(bestPayNotifyBean.getRETNCODE());
		soucreString.append("&RETNINFO=");
		soucreString.append(bestPayNotifyBean.getRETNINFO());
		soucreString.append("&TRANDATE=");
		soucreString.append(bestPayNotifyBean.getTRANDATE());
		soucreString.append("&KEY=");
		soucreString.append(PayGateWayCallService.autoTestKey);
		String SIGN=TestDataManager.getMD5(soucreString.toString().getBytes());
		bestPayNotifyBean.setSIGN(SIGN.toUpperCase());
		String formatString=FormatUtil.beanToHttpString(bestPayNotifyBean, true);
		return formatString;
	}
	/**
	 * 宝付Notify
	 * 
	 * @param aqb
	 * @return
	 * @throws InterruptedException
	 */
	public static BaoFuNotifyBean initBaoFuNotifyBean(AcquireOrderBean aqb)
			throws InterruptedException {
		BaoFuNotifyBean baoFuNotifyBean = new BaoFuNotifyBean();

		// trandno 是PaymentId
		// PPBussinessorder ppb = new
		// PayGateWayWapper().selectPPBussinessorderByTraceId(aqb.getTraceId()).get(0);
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(
				aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();

		// setBuyer_email
		baoFuNotifyBean.setAccount_no(TestDataManager.getEmail());
		baoFuNotifyBean.setAdditional_info("");
		baoFuNotifyBean.setBank_voucher_no(TestDataManager.getRandomUUID()
				.toString());
		// setBuyer_id
		baoFuNotifyBean.setBuyer_id("2088" + TestDataManager.getRandomNum(10));
		baoFuNotifyBean.setData_type("json");
		// 宝付商户号
		baoFuNotifyBean.setMember_id(BaoFu_MERID);
		// 1：借记卡 2：贷记卡 3：其 他（余额）
		baoFuNotifyBean.setPay_type("1");
		baoFuNotifyBean.setReq_reserved("");
		// 0000代表成功
		baoFuNotifyBean.setResp_code("0000");
		baoFuNotifyBean.setResp_msg("交易成功");
		// 分为单位
		Integer price = new BigDecimal(aqb.getPayPrice()).multiply(
				new BigDecimal(100)).intValue();
		baoFuNotifyBean.setSucc_amt(price.toString());
		// 宝付终端号branchNo
		baoFuNotifyBean.setTerminal_id(BaoFu_TerminalID);
		baoFuNotifyBean.setTrade_date(YMTDateUtil.getSysTime("yyyyMMddHHmmss"));
		baoFuNotifyBean.setTrans_id(trandno);
		baoFuNotifyBean.setTxn_sub_type("08");
		baoFuNotifyBean.setTxn_type("20199");
		baoFuNotifyBean.setVersion("4.0.0.0");
		baoFuNotifyBean.setVoucher_no(TestDataManager.getRandomUUID()
				.toString().replaceAll("-", ""));
		baoFuNotifyBean.setOrder_id(TestDataManager.getRandomUUID().toString());
		// alinotifyBean.setBody("自动化测试订单");
		// alinotifyBean.setBusiness_scene("qrpay");
		// alinotifyBean.setBuyer_email(TestDataManager.getEmail());
		// alinotifyBean.setBuyer_id("2088" + TestDataManager.getRandomNum(10));
		// alinotifyBean.setDiscount("0");
		// alinotifyBean.setExtra_common_param("自动化测试回传参数");
		// alinotifyBean.setGmt_close(YMTDateUtil.getBeforeOrNextDay(1));
		// alinotifyBean.setGmt_create(YMTDateUtil.getBeforeOrNextSecond(1));
		// alinotifyBean.setGmt_payment(YMTDateUtil.getBeforeOrNextSecond(2));
		// alinotifyBean.setGmt_refund(null);
		// alinotifyBean.setIs_total_fee_adjust("N");
		// alinotifyBean.setNotify_id(TestDataManager.getClientpaymentId());
		// alinotifyBean.setNotify_time(YMTDateUtil.getBeforeOrNextSecond(3));
		// alinotifyBean.setNotify_type("trade_status_sync");
		// // trandno 是PaymentId
		// // PPBussinessorder ppb = new
		// //
		// PayGateWayWapper().selectPPBussinessorderByTraceId(aqb.getTraceId()).get(0);
		// PPBussinessOrder ppb = new
		// PayGateWayWapper().selectPPBussinessorderByOrderId(aqb.getOrderId()).get(0);
		// String businessoid = ppb.getBussinessOrderId();
		// PPPayment ppm = new
		// PayGateWayWapper().selectPPPaymentByBussinessOrderId(businessoid).get(0);
		// String trandno = ppm.getPaymentId();
		// alinotifyBean.setOut_trade_no(trandno);
		// alinotifyBean.setPayment_type("1");
		// alinotifyBean.setPrice(aqb.getPayPrice());
		// alinotifyBean.setQuantity("1");
		// alinotifyBean.setRefund_status(null);
		// alinotifyBean.setSeller_email(PayGateWayCallService.Alipay_EMAIL);
		// alinotifyBean.setSeller_id(PayGateWayCallService.Alipay_MERID);
		// alinotifyBean.setSubject(aqb.getProductName());
		// alinotifyBean.setTotal_fee(aqb.getPayPrice());
		// alinotifyBean.setTrade_no(TestDataManager.getRandomUUID().toString());
		// alinotifyBean.setTrade_status("TRADE_SUCCESS");
		// alinotifyBean.setUse_coupon("N");
		return baoFuNotifyBean;
	}
	/**
	 * warmup 预热接口,防止  java.net.SocketException: Connection reset
	 */
	public static void callWarmup() {

		YmatouEasyCall call = new YmatouEasyCall("", "GET", "PARAM");
		call.setUrl("http://mockforpay.iapi.ymatou.com/warmup");
		call.setData("");
		try {
			call.callService();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String... args) throws Exception {
		SFTNotifyBean sftb = PayGateWayCallService.initSFTNotifyBean(new AcquireOrderBean() {{
			setOrderId("3533730485982891");
		}});
		sftb.setTraceNo("51d5fd05-68e1-482e-8fb5-792e4f0ce9c1");
		sftb.setSendTime("20191209114705");
		sftb.setOrderNo("19120911452630545");
		sftb.setOrderAmount("0.03");
		sftb.setTransNo("C20191209114526298642");
		sftb.setTransAmount("0.03");
		sftb.setTransTime("20191209114701");
		sftb.setPaymentNo("CP20191209114526343117");
		
		String send = PayGateWayCallService.SFTPayNotifyBeanToSend(sftb);
		Logger.debug(send);
	}
}
